m4-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Maintaining global state with m4 macros


From: Douglas McIlroy
Subject: Re: Maintaining global state with m4 macros
Date: Thu, 2 Dec 2021 12:44:49 -0500

define(bump,`define(`$1',incr($1))')dnl
define(counter,0)dnl
counter
bump(`counter')counter
bump(`counter')counter

On Thu, Dec 2, 2021 at 11:49 AM Grant Taylor via Discussion list for
the GNU M4 <m4-discuss@gnu.org> wrote:
>
> Hi,
>
> On 12/2/21 7:11 AM, Paolo Amoroso wrote:
> > Is it possible to create an m4 macro expanding to the next integer
> > of a global counter each time it's called?
>
> I don't know.
>
> I /feel/ like it should be possible.
>
> But my brain is definitely not in m4 mode this morning.
>
> > In other words, assuming the counter has an initial value (e.g. 0),
> > these calls to such a nextcount macro:
> >
> >      First call: nextcount
> >      Second call: nextcount
> >      Third call: nextcount
> >
> > should generate the following output:
> >
> >      First call: 1
> >      Second call: 2
> >      Third call: 3
> >
> > I'm stumped as I'm not sure updating the global state of a counter
> > is even possible with m4. Is there any way?
>
> It sounds like you have some code that you're working on.  Can you share
> a (sanitized version of) it so that we know how you're doing things and
> how complex / level of nesting the environment you're working on is?
>
>
>
> --
> Grant. . . .
> unix || die
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]