On Wed, May 14, 2025 at 07:42:07AM -0500, Eric Blake wrote:
> > P.S. The latest version v0.3.6 supports -D and $@ and $*, although I
> > have not implemented tail-call recursion yet. (To be frank, I'm not
> > sure how to do that, I'll have to look into it)
> 
> Based on my initial testing, you aren't correctly rescanning macro
> output, and you're eating too much whitespace:
> 
> $ m4
> define(`foreach', `ifelse(`$2', `', `', `$1(`$2')`'$0(`$1', 
> shift(shift($@)))')')dnl
> define(`echo', `$*.')dnl
> foreach(`echo', 1, 2, `3 4', (5, 6), `7, 8')
> 1.2.3 4.(5, 6).7, 8.
> echo((5, 6))
> (5, 6).
> $ m4p
> define(`foreach', `ifelse(`$2', `', `', `$1(`$2')`'$0(`$1', 
> shift(shift($@)))')')dnl
> define(`echo', `$*.')dnl
> foreach(`echo', 1, 2, `3 4', (5, 6), `7, 8')
> 1.
> echo((5, 6)
> (5,6).

Or maybe it is nested shift that is broken:
$ m4p
shift(1, 2, 3)
2,3
shift(shift(1, 2, 3))

$

the second one should have output 3, not empty.  Maybe that means your
output of $@ is wrong (conceptually, "1, 2, 3" passed to $* should
result in "1,2,3"; and passed to $@ should result in "`1',`2',`3'",
and NOT "``1,2,3''").

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


Reply via email to