Re: diversion while collecting arguments

Douglas McIlroy <[email protected]> Fri, 21 Jun 2024 18:42:59 -0400
Newsgroups gmane.comp.gnu.m4.general
Message-ID <CAKH6PiXPygX8mQnOt4Y-3GNKXo7yjVU1-jXiiJRHX+V-PxU=NQ@mail.gmail.com>
--00000000000031c345061b6e28e8
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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 external output (not via macro expansion). "Somewhat like" recognizes
the fact that a new define() for an old name replaces text, whereas a new
divert() to the same destination adds text.

I hope this helps.

Doug.



On Thu, Jun 20, 2024 at 12:21=E2=80=AFPM Ren=C3=A9 Nyffenegger <mail@reneny=
ffenegger.ch>
wrote:

> I have a file with the following content:
>
> define(show_arguments, `arg-1 =3D $1
> arg-2 =3D $2
> ')
>
> divert(1)A`'divert(0)a
>
> show_arguments(
>    divert(1)X`'divert(0)1st,
>    divert(1)Y`'divert(0)2nd)
>
> divert(1)B`'divert(0)b
>
> - - - - -
>
> m4 processes this file to:
>
> a
>
> arg-1 =3D X1st
> arg-2 =3D Y2nd
>
>
> b
> AB
>
> - - - - - -
>
> I expected the
>      divert(1)X`'divert(0)
> and
>      divert(1)Y`'divert(0)2nd)
>
> to divert the X and Y so that it is emitted at the end.
>
> Can someone explain why this is not the case?
>
> Thanks
>
> Rene
>
>
>

--00000000000031c345061b6e28e8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">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 def=
initions. divert() affects only the (normally) external output flow, captur=
ing it instead somewhat like a macro definition--but eventually simply copi=
ed to the external output (not via macro expansion). &quot;Somewhat like&qu=
ot; recognizes the fact that a new define() for an old name replaces text, =
whereas a new divert() to the same destination adds text.<div><br></div><di=
v>I hope this helps.</div><div><br></div><div>Doug.<div><br></div><div><br>=
</div></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"=
gmail_attr">On Thu, Jun 20, 2024 at 12:21=E2=80=AFPM Ren=C3=A9 Nyffenegger =
&lt;<a href=3D"mailto:[email protected]">[email protected]</a>&=
gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0=
px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I hav=
e a file with the following content:<br>
<br>
define(show_arguments, `arg-1 =3D $1<br>
arg-2 =3D $2<br>
&#39;)<br>
<br>
divert(1)A`&#39;divert(0)a<br>
<br>
show_arguments(<br>
=C2=A0=C2=A0 divert(1)X`&#39;divert(0)1st,<br>
=C2=A0=C2=A0 divert(1)Y`&#39;divert(0)2nd)<br>
<br>
divert(1)B`&#39;divert(0)b<br>
<br>
- - - - -<br>
<br>
m4 processes this file to:<br>
<br>
a<br>
<br>
arg-1 =3D X1st<br>
arg-2 =3D Y2nd<br>
<br>
<br>
b<br>
AB<br>
<br>
- - - - - -<br>
<br>
I expected the<br>
=C2=A0=C2=A0=C2=A0=C2=A0 divert(1)X`&#39;divert(0)<br>
and<br>
=C2=A0=C2=A0=C2=A0=C2=A0 divert(1)Y`&#39;divert(0)2nd)<br>
<br>
to divert the X and Y so that it is emitted at the end.<br>
<br>
Can someone explain why this is not the case?<br>
<br>
Thanks<br>
<br>
Rene<br>
<br>
<br>
</blockquote></div>

--00000000000031c345061b6e28e8--