Hi Eric, * Eric Blake wrote on Wed, Aug 06, 2008 at 05:55:46PM CEST: > Then, I finally figured out how to make m4_cond linear for m4 1.4.x, as well > as > making it use fewer macro expansions for m4 1.6.
> 2008-08-06 Eric Blake <[EMAIL PROTECTED]> > > + Add linear m4_cond for m4 1.4.x. > + * lib/m4sugar/m4sugar.m4 (m4_cond): Split into... > + (_m4_cond): ...this, for fewer macros per iteration. > + * lib/m4sugar/foreach.m4 (_m4_cond): New implementation. > + * tests/m4sugar.at (recursion): Test it. > + * NEWS: Document the linear guarantee. > + > --- a/lib/m4sugar/m4sugar.m4 > +++ b/lib/m4sugar/m4sugar.m4 > @@ -449,8 +449,14 @@ m4_define([_m4_cdr], > m4_define([m4_cond], > [m4_if([$#], [0], [m4_fatal([$0: cannot be called without arguments])], > [$#], [1], [$1], > - [$#], [2], [m4_fatal([$0: missing an argument])], > - [m4_if($1, [$2], [$3], [$0(m4_shift3($@))])])]) > + m4_eval([$# % 3]), [2], [m4_fatal([$0: missing an argument])], > + [_$0($@)])]) > + > +m4_define([_m4_cond], > +[m4_if(($1), [($2)], [$3], > + [$#], [3], [], > + [$#], [4], [$4], > + [$0(m4_shift3($@))])]) Sorry, but I fail to understand this. Why does the first line of the m4_if put its arguments in parentheses, and why is the first argument not bracket-quoted? The added test doesn't seem to expose this need. Thanks, Ralf
