[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem embedding argument inside nested macro def's

From: Eric Blake
Subject: Re: problem embedding argument inside nested macro def's
Date: Sat, 28 Jun 2008 06:38:51 +0000

From: "Piotr Wysocki":

Hello Piotr,

[you caught me on vacation, but I can answer this anyway]

> Hi,
> I have a problem. This is my code:
> What I meant is to define ___DEF macro, whose argument will
> be used in creating another macro (__T in the above example),
> which will be a macro creating a simple macro (without args).
> I would like the last expression to result in "aabc".
> The problem is that the last `$1' is expanded into `T'. I would
> rather like to expand it later.

This has come up before; in fact, the git repository now has an
example in the manual that does the very task of defining a
macro with deferred $1 expansion:

But that example was not added until after the 1.4.11 release,
so hopefully reading a texinfo diff is not too confusing, until
such time as a new release is made and the online manual
updated to contain the same example rendered in html.

> What is the correct syntax to achieve my goal?

You need to use a helper macro, and supply any instance of
$ followed by a special character that must appear literally
in the nested define as independent literally-quoted strings
in the forwarding macro.  Something like this (but untested,
since I'm not at my regular computer):


define(`___DEF', `_$0(`$1', `$'`1')')
define(`____DEF', `define(`__$1', `define(`_a$2', `a$2')')')


Note how ___DEF now calls ____DEF with two arguments,
the `$1' argument handed to ___DEF, and the literal argument
consisting of `$' concatenated with `1'.  That way, in ____DEF,
use of $1 refers to the argument of ___DEF, and use of $2 refers
to the deferred string $1 for use in the second round of defines.

Eric Blake

reply via email to

[Prev in Thread] Current Thread [Next in Thread]