m4-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Macro argument quoting and ifelse condtional


From: Gary V. Vaughan
Subject: Re: Macro argument quoting and ifelse condtional
Date: Fri, 24 Dec 2004 23:23:01 +0000
User-agent: Mozilla Thunderbird 1.0 (Macintosh/20041206)

Bill McCarty wrote:
Hi all,

I'm new to m4 and finding an apparently common idiom
confusing. Can someone help me understand it?

Assuming quotes have been replaced by << and >>, a
typical macro definition of the sort that puzzles me
reads as follows:

define(<<_CF_OUTPUT>>, <<dnl
ifelse(_CF_$1, <<_CF_$1>>, <<>>, <<
divert
CF_$1_OUTPUT
divert(-1)

)>>)dnl

dnl

I'm particularly puzzled by the distinction between
the first two arguments of ifelse: _CF_$1 and
<<_CF_$1>>. The ifelse seems to cause the macro to
expand to void unless its argument is double-quouted,
like <<<<TEST>>>>. But, in actual use contexts, its
argument seems generally to be single-quoted. So,
genius that I am <g>, I conclude that I'm missing
something. But, I can't see what.

_CF_OUTPUT(test)
  -> ifelse(_CF_test, <<_CF_test>>, <<>>, ...

as each arg is parsed one level of quoting is removed, as
each is evaluated another level of quoting is removed.  So
we eventually compare:
    _CF_test and _CF_test

hence the 3rd arg is evaluated.

Similarly for _CF_OUTPUT(<<test>>)
  -> ifelse(_CF_<<test>>, <<_CF_test>>, <<>>, ...


However:

_CF_OUTPUT(<<<<test>>>>)
  -> ifelse(_CF_<<<<test>>>>, <<_CF_<<<<test>>>>, <<>>, ...

2 levels of quotes are removed before the comparison, hence:

  _CF_test and __CF_<<test>>

are compared, so the 4th argument of ifelse is evaluated.

HTH,
        Gary.
--
Gary V. Vaughan      ())_.  address@hidden,gnu.org}
Research Scientist   ( '/   http://tkd.kicks-ass.net
GNU Hacker           / )=   http://www.gnu.org/software/libtool
Technical Author   `(_~)_   http://sources.redhat.com/autobook

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]