[Top][All Lists]
[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:40:25 +0000 |
User-agent: |
Mozilla Thunderbird 1.0 (Macintosh/20041206) |
Hmm, it's late and I'm not thinking clearly. Let me correct
my last mail slightly:
Gary V. Vaughan wrote:
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>>, <<>>, ...
-> ifelse(_CF_test, _CF_test, , ...
as each arg
to _CF_OUTPUT
is parsed one level of quoting is removed, as each is
reparsed from the resulting ifelse expansion,
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>>, <<>>, ...
-> ifelse(_CF_test, _CF_test, , ...
However:
_CF_OUTPUT(<<<<test>>>>)
-> ifelse(_CF_<<test>>, <<_CF_<<test>>>>, <<>>, ...
-> ifelse(_CF_test, _CF_<<test>>, , ...
2 levels of quotes are removed before the
eventual
comparison, hence:
_CF_test and __CF_<<test>>
are compared, so the 4th argument of ifelse is evaluated.
Hopefully that clarifies as much, while remaining technically
correct! :-/
Cheers,
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
signature.asc
Description: OpenPGP digital signature