Wired behavior of `def()'
Xavier Wang <[email protected]> Wed, 13 Aug 2025 14:37:32 +0800
| Newsgroups | gmane.comp.gnu.m4.general |
|---|---|
| Message-ID | <CAPsVyB9hxspM=8U21wrYoNJi_JBrSiF-hoRM+zDsHZZjwqeXZg@mail.gmail.com> |
Hi list, After looked into the discuss 2 months ago between Nicolaos and Eric, I'm interesting to try to make a M4 implement in Rust to better understand m4 and for fun. A naive version is easy to made (I have both study the BSD implement and GNU implement together to make a better architecture). But it seems that both two implement can not well handle recursive `$@' in O(1) . So I start to study the implement of 1.6 version of GNU m4 and make a new implementation based on the idea of that version. But in the meantime of implementing, I have found a wired behavior of `defn'. The document said: > If name is a user-defined macro, the quoted definition is simply the quot= ed expansion text. If, instead, there is only one name and it is a builtin,= the expansion is a special token, which points to the builtin=E2=80=99s in= ternal definition. This token is only meaningful as the second argument to = define (and pushdef), and is silently converted to an empty string in most = other contexts. Combining a builtin with anything else is not supported; a = warning is issued and the builtin is omitted from the final expansion. But this text: define(`foo', defn(`defn') bar) it should be same as: define(`foo', bar) as the defn(`defn') expands to empty, and the whitespaces after `,' will ignored. But I found it defined a wired macro: foo =3D> foo foo() =3D> I noticed the statement: "This token is only meaningful as the second argument to define (and pushdef)", So I tried without `define': define(`foo', `[$1]-[$2]') =3D> foo( first , defn(`defn') second) =3D>[first ]-[] I think it should be expand as: =3D> [first ]-[second] or even: =3D> [first ]-[ second] So which behavior is correct? --=20 regards, Xavier Wang.