creating a macro with an unknown number of parameters

I use macros everyday, but its the first time I want to create a macro like this

I want to create a new macro whereby I can pass a variable amount of parameters

the macro (much simplified version) would be 

#define myMacro(%params)         $listBuild(any Number Of %params I pass in)

so I want to be able to call $$$myMacro(user,ID,vehicle)         ie 3 parameters would generate


but equally I might want to call that same macro $$$myMacro(companyID)          ie 1 paramter and would generate


so the question is, 

how can I create the macro without knowing how many parameters I'm passing in up front.

(Hope this makes sense)


  • 0
  • 61
  • 3
  • 1


Use def1arg macro definition:

#def1arg myMacro(%args) $lb("%args")
write $$$myMacro(a, b)

Compiles into

 write $lb("a, b")

that doesn't seem to work Eduard.

here's my macro (according to you)

#define testEmptyParams(%args)    i $listfind($listbuild("%args"),"")>0 $$$quitMissingParams
here's the call


when I compile that, I get

"Too many arguments to macro: 'testEmptyParams'"

I've tried removing the quotes inside the macro and it still says too many arguments.

so I want to do a nested $lb, and then quit with another macro $$$quitMissingParams.

because I'm testing for empty parameters, I never know how many params I want to pass in.


s a="1",b="2" i $listfind($listbuild(a,b),"")>0 w " - missing"

s a="",b="2" i $listfind($listbuild(a,b),"")>0 w " - missing"

s a="",b="2",c=3 i $listfind($listbuild(a,b,c),"")>0 w " - missing"

s a="1",b="2",c=3 i $listfind($listbuild(a,b,c),"")>0 w " - missing"

Am I missing something ?

Does my example compile for you?

Anyway, you should use #def1arg instead of #define as I suggested in the original answer.

I apologise,

I am so used to using #define, I totally missed the #def1arg

so, now I change it to this, It works fine.I hadn't come across this #def1arg before.
Its an interesting use and I can think of quite a few ways already where I can create more macros to make use of it.