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

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to