Re: Maintaining global state with m4 macros

2021-12-02 Thread Douglas McIlroy
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 wrote: > > Hi, > > On 12/2/21 7:11 AM, Paolo Amoroso wrote: > > Is it possible to create an m4 macro e

Re: diversion while collecting arguments

2024-06-21 Thread Douglas McIlroy
I think of m4 as a switchyard for data streams. There are various internal flows, e.g. to or from arguments, and to or from macro definitions. divert() affects only the (normally) external output flow, capturing it instead somewhat like a macro definition--but eventually simply copied to the extern

nonuniform behavior of builtins

2024-09-10 Thread Douglas McIlroy
It is annoying that various builtin macros don't argument lists like ordinary macros do. dnl complains if given an argument list--even an empty one. info m4 has a long discussion about how dnl treats arguments, even though the treatment is exactly the same as for non-builtin macros. When the argum

Re: input file ends with non-newline

2024-12-09 Thread Douglas McIlroy
hide the ERROR diagnostics mentioned above. But I don't think it's necessary to support the portability of fatal errors. Doug On Sat, Dec 7, 2024 at 11:02 PM Eric Blake wrote: > > On Fri, Dec 06, 2024 at 05:33:09PM -0500, Douglas McIlroy wrote: > > Arguments are c

input file ends with non-newline

2024-12-06 Thread Douglas McIlroy
Arguments are collected if a macro name is "immediately" followed by a left parenthesis. Experiment shows that arguments are not collected when a macro name occurs at the end of a file (without a following newline) and the next input file begins with a left parenthesis. I believe this behavior is i

Re: Perhaps it is time for a beta release of ver 1.6 ?

2025-04-04 Thread Douglas McIlroy
I'm delighted to receive the progress report, and especially the mention of tail recursion. Am I right in guessing that all tail calls will benefit, so that n levels of tail recursion will use O(1) stack space rather than O(n)? Doug McIlroy On Thu, Apr 3, 2025 at 3:37 PM Eric Blake wrote: > > On

collision in define

2025-05-14 Thread Douglas McIlroy
This program define(`A', x define('A',y)A z) A produces this answer y It appears that the inner definition stamps on the outer definition in progress. I imagine that each allocates and fills a string that it assigns as the stored definition for A, The inner one, being assigned later,

Re: m4 functional programming [was: more m4p bugs]

2025-05-19 Thread Douglas McIlroy
Eric Blake wrote, "Writing a truly generic lambda() that can define an anonymous m4 macro is much tougher, because of the inability to easily generate '$1' and friends into the macro body without having it be prematurely expanded. In the literature, I have seen reference to the "M5" language, wher

New release of programming in bare m4

2025-07-25 Thread Douglas McIlroy
A new version of www.cs.dartmouth.edu/~doug/barem4.m4 enables functional programming within m4. This thoroughly annotated implementation of barem4 uses no builtin macros other than `define', thereby demonstrating that the heart of m4 is Turing complete. In particular, it provides conditional execut

Re: Is it possible to expand macro just once?

2020-10-12 Thread M Douglas McIlroy
echo foo | m4 -Dfoo=\`bar\' -Dbar=baz On Mon, Oct 12, 2020 at 8:24 AM Eric Blake wrote: > On 10/12/20 5:27 AM, Wolf wrote: > > Hello, > > > > Not subscribed to the list, so please CC. > > That's standard practice anyway ;) > > > > > I have m4 template that contains macro, that I do not know the