[metapost] accessing variables in nested macros
mojca.miklavec.lists at gmail.com
Sat Feb 10 17:26:55 CET 2007
On 2/9/07, Stephan Hennig wrote:
> within two macros that share the same initialization calculations I want
> to put those calculations into a new macro called "init". Now, I don't
> want to pass a whole bunch of variables to "init" and tried a simple def
> declaration in the hope that "init" then shares the context (group and
> variables) of the calling macro. That is, I expected
> def init=
> vardef calcA(expr parameters)=
> when called, more or less to literally replace "init;" by "calculation;"
> and therefore accessing variables from "calcA" in "init" should be ok.
> However, in the example below I can't access variables from the calling
> macro. What's wrong with my definition?
> Best regards,
> Stephan Hennig
> def init=
> %%% Variable b should be saved with respect to the
> %%% local group of the calling vardef macro.
> save b;
> numeric b;
> b := a + 1;
> vardef calcA(expr a)=
> show "a = " & decimal a;
> % show "b = " & decimal b;
I don't know if I understood your question properly. Are you looking
for something like the following code?
b := a + 1;
def calcA(expr aa)=
save a; numeric a; a := aa;
save b; numeric b;
show "a = " & decimal a;
show "b = " & decimal b;
More information about the metapost