GNU Info

Info Node: (m4.info)Arguments

(m4.info)Arguments


Next: Pseudo Arguments Prev: Define Up: Definitions
Enter node , (file) or (file)node

Arguments to macros
===================

   Macros can have arguments.  The Nth argument is denoted by `$n' in
the expansion text, and is replaced by the Nth actual argument, when
the macro is expanded.  Here is a example of a macro with two
arguments.  It simply exchanges the order of the two arguments.

     define(`exch', `$2, $1')
     =>
     exch(arg1, arg2)
     =>arg2, arg1

   This can be used, for example, if you like the arguments to `define'
to be reversed.

     define(`exch', `$2, $1')
     =>
     define(exch(``expansion text'', ``macro''))
     =>
     macro
     =>expansion text

   Note: Quoting Arguments, for an explanation of the double quotes.

   GNU `m4' allows the number following the `$' to consist of one or
more digits, allowing macros to have any number of arguments.  This is
not so in UNIX implementations of `m4', which only recognize one digit.

   As a special case, the zero'th argument, `$0', is always the name of
the macro being expanded.

     define(`test', ``Macro name: $0'')
     =>
     test
     =>Macro name: test

   If you want quoted text to appear as part of the expansion text,
remember that quotes can be nested in quoted strings.  Thus, in

     define(`foo', `This is macro `foo'.')
     =>
     foo
     =>This is macro foo.

The `foo' in the expansion text is _not_ expanded, since it is a quoted
string, and not a name.


automatically generated by info2www version 1.2.2.9