m4: Quoting Arguments

1 
1 4.4 On Quoting Arguments to macros
1 ==================================
1 
1 Each argument has unquoted leading whitespace removed.  Within each
1 argument, all unquoted parentheses must match.  For example, if FOO is a
1 macro,
1 
1      foo(() (`(') `(')
1 
1 is a macro call, with one argument, whose value is '() (() ('.  Commas
1 separate arguments, except when they occur inside quotes, comments, or
1 unquoted parentheses.  ⇒Pseudo Arguments, for examples.
1 
1    It is common practice to quote all arguments to macros, unless you
1 are sure you want the arguments expanded.  Thus, in the above example
1 with the parentheses, the 'right' way to do it is like this:
1 
1      foo(`() (() (')
1 
1    It is, however, in certain cases necessary (because nested expansion
1 must occur to create the arguments for the outer macro) or convenient
1 (because it uses fewer characters) to leave out quotes for some
1 arguments, and there is nothing wrong in doing it.  It just makes life a
1 bit harder, if you are not careful to follow a consistent quoting style.
1 For consistency, this manual follows the rule of thumb that each layer
1 of parentheses introduces another layer of single quoting, except when
1 showing the consequences of quoting rules.  This is done even when the
1 quoted string cannot be a macro, such as with integers when you have not
1 changed the syntax via 'changeword' (⇒Changeword).
1 
1    The quoting rule of thumb of one level of quoting per parentheses has
1 a nice property: when a macro name appears inside parentheses, you can
1 determine when it will be expanded.  If it is not quoted, it will be
1 expanded prior to the outer macro, so that its expansion becomes the
1 argument.  If it is single-quoted, it will be expanded after the outer
1 macro.  And if it is double-quoted, it will be used as literal text
1 instead of a macro name.
1 
1      define(`active', `ACT, IVE')
1      =>
1      define(`show', `$1 $1')
1      =>
1      show(active)
1      =>ACT ACT
1      show(`active')
1      =>ACT, IVE ACT, IVE
1      show(``active'')
1      =>active active
1