m4: Builtin
1
1 5.8 Indirect call of builtins
1 =============================
1
1 Builtin macros can be called indirectly with 'builtin':
1
1 -- Builtin: builtin (NAME, [ARGS...])
1 Results in a call to the builtin NAME, which is passed the rest of
1 the arguments ARGS. If NAME does not name a builtin, an error
1 message is printed, and the expansion is void.
1
1 The macro 'builtin' is recognized only with parameters.
1
1 This can be used even if NAME has been given another definition that
1 has covered the original, or been undefined so that no macro maps to the
1 builtin.
1
1 pushdef(`define', `hidden')
1 =>
1 undefine(`undefine')
1 =>
1 define(`foo', `bar')
1 =>hidden
1 foo
1 =>foo
1 builtin(`define', `foo', defn(`divnum'))
1 =>
1 foo
1 =>0
1 builtin(`define', `foo', `BAR')
1 =>
1 foo
1 =>BAR
1 undefine(`foo')
1 =>undefine(foo)
1 foo
1 =>BAR
1 builtin(`undefine', `foo')
1 =>
1 foo
1 =>foo
1
1 The NAME argument only matches the original name of the builtin, even
11 when the '--prefix-builtins' option (or '-P', ⇒Invoking m4
Operation modes.) is in effect. This is different from 'indir', which
1 only tracks current macro names.
1
1 $ m4 -P
1 m4_builtin(`divnum')
1 =>0
1 m4_builtin(`m4_divnum')
1 error->m4:stdin:2: undefined builtin `m4_divnum'
1 =>
1 m4_indir(`divnum')
1 error->m4:stdin:3: undefined macro `divnum'
1 =>
1 m4_indir(`m4_divnum')
1 =>0
1
1 Note that 'indir' and 'builtin' can be used to invoke builtins
1 without arguments, even when they normally require parameters to be
1 recognized; but it will provoke a warning, and result in a void
1 expansion.
1
1 builtin
1 =>builtin
1 builtin()
1 error->m4:stdin:2: undefined builtin `'
1 =>
1 builtin(`builtin')
1 error->m4:stdin:3: Warning: too few arguments to builtin `builtin'
1 =>
1 builtin(`builtin',)
1 error->m4:stdin:4: undefined builtin `'
1 =>
1 builtin(`builtin', ``'
1 ')
1 error->m4:stdin:5: undefined builtin ``'
1 error->'
1 =>
1 indir(`index')
1 error->m4:stdin:7: Warning: too few arguments to builtin `index'
1 =>
1