On 01/11/2012 09:36 AM, jfw wrote:
> I've been programming for about 45 years. I've been programming about 2 days
> with M4.
> I want to increment or double a "variable" every time I call a macro.
> A paper "Exploiting the m4 Macro Language" by Kenneth J. Turner available on
> the web suggests:
That looks like the paper you are reading has used a different
typography than what m4 expects for its default quoting characters. Are
you sure you are using backtick/apostrophe (ASCII values 0x60/0x39) and
not the Unicode single-quote characters in your actual script? Or are
you using changequote() to select alternate quotes?
But given your description of your stack overflow, I assume you are
using the correct quoting in your script. Rather, your problem is one
> then invoking it with
It sounds like you _wanted_ to re-define the variable Count to be the
value obtained by incrementing the previous contents of Count. But that
Notice that the second argument is _not_ quoted - I want incr(Count) to
be expanded and its _result_ used as an argument to define(). But in
what you wrote, you ended up defining Count to the literal string
"incr(Count)" rather than a numeric value; therefore, when you later
typed Count to cause it to be macro expanded, you triggered an infinite
expansion: Count expands to incr(Count) expands to incr(incr(Count)),
etc., until you have stack overflow.
Now you are really worrying me - you've mixed two different quoting
styles in the same define() line, which makes me suspect that you really
aren't using the right bytes consistently. But the warning is correct:
here, you are attempting to call incr with a single argument of the
literal string "Count", when you really meant to be calling it with a
single argument which is the number produced by the expansion of the
pre-existing macro Count. That is, you want incr(Count) and not
> also produces stack overflow
> I would appreciate being told the simple idiom I am trying to write. Once I
> understand incr() I assume I could use eval(x *2) to produce doubling