Re: Maintaining global state with m4 macros

Grant Taylor via Discussion list for the GNU M4 <[email protected]> Thu, 2 Dec 2021 09:36:56 -0700
Newsgroups gmane.comp.gnu.m4.general
Organization TNet Consulting
Message-ID <[email protected]>
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
smime.p7s (application/pkcs7-signature, 3.9 KB) - not displayed