how to rescan m4 data for recursive macro inplace substitution

Viewed 145

I have this very simple code.

define(`S',`some')
define(`T',`thing')
define(`D',`doing')
define(`something',`st_todo') 
define(`st_tododoing',`done!')
S`'T 
OR 
S()T() 

the actual end result is

something 
OR 
something 

but expected recursive substitution result as

st_todo

how I can rescan the code to the input again ?

maybe the "indir", But its A crooked nasty solution:

indir(S()`'T()`'D())

the result is:

--NOTHING--

maybe the so called command "divert", can make the output, recycled to input ?

of course the reviews says it is "inplace macro substitution", BUT the result are different.

of course we can use "C" language primitive macro solution. EG:

define(`concat',`$1$2$2$4$5')

BUT this "concat" "solution", will increase the code NESTING complexity, in a large code reconstruction. EG:

concat(concat(S1,T1),concat(S2,T2,more1,more2,...))

WHAT if we have "concat" of 10 words OR more OR with conditionals "ifelse" ?.

M4 concept is beyond the old "C" preprocessor!

the real solution must come from the macro "inside core system"

any idea ?

1 Answers

M4 does rescan. However, the empty string `' ends the preceding token, and thus prevents some and thing from being recognised as a single token.

Instead, concatenate the macro expansions using another macro:

define(`concat',`$1$2')
define(`S',`some')
define(`T',`thing')
define(`something',`st_todo') 
concat(S,T)
$ m4<<"EOF"
> define(`concat',`$1$2')dnl        
> define(`S',`some')dnl
> define(`T',`thing')dnl
> define(`something',`st_todo')dnl
> concat(S,T)
> EOF
st_todo

Related