Next: , Previous: Pushdef, Up: Definitions


4.7 Indirect call of macros

Any macro can be called indirectly with indir:

— Builtin: indir (name, ...)

Results in a call to the macro name, which is passed the rest of the arguments. If name is not defined, an error message is printed, and the expansion is void.

The macro indir is recognized only with parameters.

This can be used to call macros with computed or “invalid” names (define allows such names to be defined):

     define(`$$internal$macro', `Internal macro (name `$0')')
     =>
     $$internal$macro
     =>$$internal$macro
     indir(`$$internal$macro')
     =>Internal macro (name $$internal$macro)

The point is, here, that larger macro packages can have private macros defined, that will not be called by accident. They can only be called through the builtin indir.

One other point to observe is that argument collection occurs before indir invokes name, so if argument collection changes the value of name, that will be reflected in the final expansion. This is different than the behavior when invoking macros directly, where the definition that was in effect before argument collection is used.

     define(`f', `1')
     =>
     f(define(`f', `2'))
     =>1
     indir(`f', define(`f', `3'))
     =>3
     indir(`f', undefine(`f'))
     error-->m4:stdin:4: undefined macro `f'
     =>