On Wed, May 14, 2025 at 9:42 AM Eric Blake <ebl...@redhat.com> wrote:
>
> 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''").

Thank you!

I think I fixed this bug in 0.5.4 just now. There were a couple of
things I had gotten wrong, perhaps the most stark was that I was
running the parser on secondary parentheses, giving incorrect results
e.g. for len((2, 3)) (should be 6).

I will fix the // issue next.

Regards,
Nikolaos Chatzikonstantinou

Reply via email to