Re: Print literal $0 value

Grant Taylor <[email protected]> Sat, 7 Jul 2018 19:15:51 -0600
Newsgroups gmane.comp.gnu.m4.general
Organization TNet Consulting
Message-ID <[email protected]>
On 07/07/2018 05:29 PM, Charlie Sale wrote:
> Hello M4

Hi,

> I am trying to write an m4 macro that has the literal $0 character in 
> its expansion. Basically, I'm trying to do something like this:
> 
> define(`my_macro', `/$1/ { print $0 }')
> my_macro(`foo')
> --> /foo/ { print $0 }
> 
> Whenever I use the above macro, it turns into this unterminating recursive 
> loop that re-expands the macro in the back. I am aware that the token 
> $0 prints the name of the defined macro in M4, but I would like to print 
> the literal characters instead. How can I do this?

Does the following do what you want?

define(`my_macro', `/$1/ { print $`'0 }')

Each additional `' delays expansion until the next round of parsing.  So 
you could end up with something like this:

define(`my_macro', `/$1/ { print $````''''0 }')

What happens is the inner most `' is removed each parse cycle.  So the 
above would only expand $0 on the 5th parsing cycle.  (If you had that 
many.)

At least that's my understanding.



-- 
Grant. . . .
unix || die
smime.p7s (application/pkcs7-signature, 3.9 KB) - not displayed