Is it possible to define a m4 macro (without arguments), which expands to 1 on first invocation, expands to 2 on second invocation, and so on? In other words, it should have internal memory storing the number of times it is invoked. Can this be done?
You can do that by having two macros, a
counter holding the current value, and a
count macro that expands to the value and redefines `counter'. For example, it could look like this
count macro is used, it firstly redefines
counter to hold its next value (adding 1 to its present value), and then it uses that value.
I'm not immediately sure how to do this with a single macro, and if that's an important aspect of your problem then this is not the answer.