[metapost] accessing variables in nested macros
Stephan Hennig
mailing_list at arcor.de
Sat Feb 10 15:46:40 CET 2007
Ryan Van Wagoner schrieb:
>>>>>> "Stephen Hennig" == Stephan Hennig <mailing_list at arcor.de> writes:
>
> Your problem appears to be related to scoping, although I am not
> familiar with how scope works in MetaPost.
Thanks for looking into this.
> However, if you change your definition of "init" slightly
> to something that should behave identically, it highlights that the
> problem is that the variable "a" is not available to the expansion of
> "init".
>
> def init =
> save b;
> numeric b;
> scantokens("b := " & decimal a & " + 1;");
> enddef;
> ;
> [...]
> So even though your expanded "init" macro should be parsed and digested
> in the scope of the vardef where "a" is bound to the argument of the
> macro, it is not. Note that if you move the scantokens line into the
> definition of calcA, it works as expected. However, if you use instead:
>
> scantokens("b := a + 1;");
>
> inside your calcA definition, you get the same error as shown above.
Because a isn't substituted inside strings? Your observations seem to
be nice exercises for The MetaFontbook.
Best regards,
Stephan Hennig
More information about the metapost
mailing list