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

4.4 On Quoting Arguments to macros

Each argument has unquoted leading whitespace removed. Within each argument, all unquoted parentheses must match. For example, if foo is a macro,

foo(() (`(') `(')

is a macro call, with one argument, whose value is ‘() (() (’. Commas separate arguments, except when they occur inside quotes, comments, or unquoted parentheses. See section Special arguments to macros, for examples.

It is common practice to quote all arguments to macros, unless you are sure you want the arguments expanded. Thus, in the above example with the parentheses, the ‘right’ way to do it is like this:

foo(`() (() (')

It is, however, in certain cases necessary (because nested expansion must occur to create the arguments for the outer macro) or convenient (because it uses fewer characters) to leave out quotes for some arguments, and there is nothing wrong in doing it. It just makes life a bit harder, if you are not careful to follow a consistent quoting style. For consistency, this manual follows the rule of thumb that each layer of parentheses introduces another layer of single quoting, except when showing the consequences of quoting rules. This is done even when the quoted string cannot be a macro, such as with integers when you have not changed the syntax via changeword (see section Changing the lexical structure of words).

The quoting rule of thumb of one level of quoting per parentheses has a nice property: when a macro name appears inside parentheses, you can determine when it will be expanded. If it is not quoted, it will be expanded prior to the outer macro, so that its expansion becomes the argument. If it is single-quoted, it will be expanded after the outer macro. And if it is double-quoted, it will be used as literal text instead of a macro name.

define(`active', `ACT, IVE')
⇒
define(`show', `$1 $1')
⇒
show(active)
⇒ACT ACT
show(`active')
⇒ACT, IVE ACT, IVE
show(``active'')
⇒active active

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

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

© manpagez.com 2000-2017
Individual documents may contain additional copyright information.