Hello m4 team,

I hope that it is an actual bug this time...
There is a sample listing for a simple for-
loop in the manual at chapter 6.4.
The corresponging lines are
==m4code==
$ m4 -I examples
[...]
# forloop(var, from, to, stmt) - simple version
define(`forloop', `pushdef(`$1', `$2')_forloop($@)popdef(`$1')')
define(`_forloop', `$4'`ifelse($1, `$3', `', `define(`$1', incr($1))$0($@)')')
[...]
==end==

While this code works perfectly for the most applications, it miserably fails
if the client uses something like this:
==m4code==
forloop(`a', 1, 8, `a')
=> aifelse(1, 8, , define(`a', incr(a))_forloop(`a',`1',`8',`a'))
==end==

I am aware of the existence of forloop2, which is listed in the example code
directory, but I like this function for it's simplicity.
I think the following (tested) quick fix could be suitalbe for usage in the manual.
==m4code==
[...]
define(`_forloop', `$4'``''`ifelse($1, `$3', `', `define(`$1', incr($1))$0($@)')')
[...]
==end==

Best regards
Florian Mayer

Reply via email to