m4-discuss
[Top][All Lists]
Advanced

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

Re: Macro + diversion issue


From: Daniel Richard G.
Subject: Re: Macro + diversion issue
Date: Sun, 20 May 2007 01:20:06 -0400

On Sat, 2007 May 19 21:21:31 -0600, Eric Blake wrote:
> 
> When m4 gets to the point marked by ^, it notices a macro, and expands it
> to text as it continues to collect the arguments of foo, resulting in:
> [...]
> that is, you both swapped to and back from diversion 10, all while
> collecting the argument for foo.  Finally, with the argument now in place,
> foo is invoked, as though it had been called with `text1.text2' as its
> properly quoted argument.

Okay, so that's the key point: m4 was in argument-collection mode. Nothing 
went into diversion 10 because the text was being sucked up to pass to 
foo().

> As for how to do this, I recommend that you stick with consistent quoting,
> as you already surmised.  The autoconf manual, and my recent revisions to
> the m4 manual, are serious when they say that the policy of a consistent
> interface of one level of quoting per level of parentheses is the easiest
> way to have predictable results.

I'm with you on the importance of quoting in macro definitions, as well as 
knowing how and why not quoting therein can be useful in certain cases. 
(GPP, which I used before coming here, had separate "define" and "defeval" 
builtins precisely because it lacked a quoting mechanism.)

In macro application, however, most of the time it's not a problem if macro 
args are fully expanded before invocation. And this is a good thing, 
because it would be pretty cumbersome to expect to use quotes for every 
single macro argument.

What would you think of having a builtin like

        sendtodiv(number, text)

        (or maybe a two-arg form of divert()?)

that sends its text argument to the specified diversion, *regardless of
context*, and without changing the current diversion?

(This is in fact what I was doing, albeit implemented as a composite that 
turned out not to have the "regardless" property.)

Moreover, before making use of diversions, I had implemented the footnote 
mechanism by successively appending lines of text to a "buffer" macro, e.g.

        define(`fnBuf', fnBuf`'newFootnote)  <-- look! unquoted definition

That worked perfectly. Of course, it's not ideal; diversions are better 
suited, resource-usage-wise, to this sort of incremental buffering. My 
original issue gets at why diversions cannot currently be used in the same 
way; do you think such a builtin would be a good means of making that 
possible?


--Daniel


-- 
NAME   = Daniel Richard G.       ##  Remember, skunks       _\|/_  meef?
EMAIL1 = address@hidden        ##  don't smell bad---    (/o|o\) /
EMAIL2 = address@hidden      ##  it's the people who   < (^),>
WWW    = http://www.******.org/  ##  annoy them that do!    /   \
--
(****** = site not yet online)




reply via email to

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