How to handlle Variable Number of Parameters in Macro?
Common macro def as following
#def AnyNumber(%args) for i=1:1:$listlength(%args) { Write $listget(%args, i)}
Using this marcro in objectscript code:
ClassMethod Test() as %Status {
$$$AnyNumber($lb(1,2,3))
}
if ths args is literal value , Iit worked great. But When I want pass Objects, It's not working
$$$AnyNumber($lb(##class(someClass).%New()))
I know I can pass a %ListObjects , If I want more shorter Line. How can I do this.
Tks
Discussion (1)0
Comments
For such cases use the macro: #def1arg
See this example:
Test ;my Macro test
#def1arg ADD(%a) $$add(%a)
write $$$ADD(1),!
write $$$ADD(1,2),!
write $$$ADD(1,2,3),!
write $$$ADD(1,2,3,4),!
quit
add(a,b=0,c=0,d=0) { quit a+b+c+d }do ^Testgives you the output
1
3
6
10