manpagez: man pages & more
info m4
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.7 Indirect call of macros

Any macro can be called indirectly with indir:

Builtin: indir (name, [args…]

Results in a call to the macro name, which is passed the rest of the arguments args. 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 (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.

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

When handed the result of defn (see section Renaming macros) as one of its arguments, indir defers to the invoked name for whether a token representing a builtin is recognized or flattened to the empty string.

$ m4 -d
indir(defn(`defn'), `divnum')
error-->m4:stdin:1: Warning: indir: invalid macro name ignored
indir(`define', defn(`defn'), `divnum')
error-->m4:stdin:2: Warning: define: invalid macro name ignored
indir(`define', `foo', defn(`divnum'))
indir(`divert', defn(`foo'))
error-->m4:stdin:5: empty string treated as 0 in builtin `divert'

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on September 29, 2013 using texi2html 5.0.

© 2000-2018
Individual documents may contain additional copyright information.