[metapost] Problems with passing parameters to macros

Yasir Malik ymalik at stevens.edu
Thu Dec 2 22:22:16 CET 2010


I found the problem:

> File macros.mp:
> def someMacro(expr v, a, b, x, y, z) =
> begingroup
>
> show "inside func";
> show v, a, b;
> show "";
>
> ...
>
> show "before exiting";
> show v, a, b;
> show "";
>
> endgroup
> enddef;
>
>
>
> Another file:
>
> input macros.mp
>
>
> pair a, b, ap;
>
> ...
>
> show "before calling";
> show a, b, ap;
> show "";
> someMacro(a, b, ap, x, y, z);
>
> show "after calling";
> show a, b, ap;
>
In macro someMacro, I was declaring "pair ap" but not saving it first.  I 
was then assigning ap to another value that turned out to be the same as 
b.  ap in someMacro then conflicted with ap in the main file.  I guess 
this happens because Metapost expands the macro from whereever you called 
it from, even though the macro is defined in a different file.

I'm simplifying what happened, but this was difficult to trace because ap 
was declared in a macro that was many macros up in the stack of the 
top-level macro I was calling from the main file (macro calls within 
macro calls...).

Thanks,
Yasir


More information about the metapost mailing list