Re: BUG PROBLEM-> recursive macro inplace substitution

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.bugs
Organization Red Hat, Inc.
Message-ID <[email protected]>
On 9/30/20 5:03 AM, hhmm wrote:
> please see this reference
> 
> https://stackoverflow.com/questions/64066166/how-to-rescan-m4-data-for-recursive-macro-inplace-substitution/64066869?noredirect=1#comment113299085_64066869

Better yet, ask your question directly here, instead of making every
reader chase a URL that may have a different lifetime than the mailing
list archive.

So doing that on your behalf:

> I have this very simple code.
> 
> define(`S',`some')
> define(`T',`thing')
> define(`something',`st_todo') 
> S`'T 

In the interim, this expands to:
some`'thing

and thus the scanner never gets to see "something" as a single macro name.

> OR 
> S()T() 

Partway through evaluation, this has expanded to:

someT()

but someT is not a macro name, and thus the scanner never gets to see
"something" as a single macro name.

> 
> the actual end result is
> 
> something 
> OR 
> something 

You probably meant "someT()" here, based on your examples above.

> 
> but expected recursive substitution result as
> 
> st_todo
> 
> how I can rescan the code to the input again ?

The existing answers on that topic appear to gracefully cover it: any
time you want a second macro to be expanded and that expansion
concatenated with the output of the first, for evaluating the entire
concatenation for further macros, you have to use a glue macro.

define(`concat',`$1$2')
concat(S,T)

evaluates to:

concat(`some',`thing')

which in turn evaluates to:

something

which is now a valid macro name, and finally expands to:

st_todo

If you need a macro that concatenates more than just $1 and $2, you can
write it.
https://www.gnu.org/software/m4/manual/m4-1.4.15/html_node/Shift.html#index-joining-arguments-130
documents a "join" macro shipped with the m4 documentation that can be
used with an empty separator to concatenate an arbitrary number of
arguments into a single-quoted string with no intervening `' or (); pass
that through one more macro call to perform macro expansion on the
entire string.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
signature.asc (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAl90mOMACgkQp6FrSiUn
Q2rkNgf/bTDBEO9TvNYxivM1znfV/vqNPNv7BX3k0EDqkIuTBBijx3giqvugRjiu
Y8wgg3kUWKLI78gf7vbYlpZqtZXTfLGootIvGSaqQhJqeIT09h3e6pMkdZt4EnMZ
wnTZf4jf17yVTBxaj9PSBifmwyy4clvEHoyFP9vNA9x3sEXMp893xUKGV2bffkQ5
ZEDjpjyjZB7WP2W4q36ANVMkpE7Pyr0yuiZ0nlPNnV1uD4hxSfZax38mi4HUF6Q8
DOYhzim8/fS/AdViS5enZpc0GYaGkNgwW7BlAvzB5t0vTJqfg6FZCtVxrlFb8S/V
16swpyJ1L2Eo1EW1fsgkqxgKuv+fvg==
=wcj9
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.