On Sat, Apr 05, 2025 at 10:56:40AM -0500, Eric Blake via M4-patches wrote:
> * doc/m4.texi (Incr): Document a self-updating counter.
> Suggested by Barry Davidson in
> https://lists.gnu.org/archive/html/bug-m4/2023-08/msg00005.html
> ---
>  doc/m4.texi | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 

> +@example
> +define(`_counter', `-1')dnl
> +define(`counter', `ifelse(`$#', `0', `define(`_$0', incr(_$0))_$0`'',
> +`define(`_$0', decr(`0$1'))')')

Hmm. This works for blank and non-negative values, but fails for
negative seeds. I'll rewrite it to use eval($1-1) rather than
decr(0$1) to be a bit more robust.

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


_______________________________________________
M4-patches mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/m4-patches

Reply via email to