[metapost] Problems with passing parameters to macros

Yasir Malik ymalik at stevens.edu
Thu Dec 2 15:15:09 CET 2010


Hi,

I'm seeing strange behavior when I pass parameters to a macro.  Consider 
the following code fragment:

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;

Here's the output:

>> "before calling"
>> (-22.32306,38.6648)
>> (-128.55247,0)
>> (-37.20473,64.44066)
>> ""
>> "inside func"
>> (-22.32306,38.6648)
>> (-128.55247,0)
>> (-37.20473,64.44066)
>> ""
>> "before exiting"
>> (-22.32306,38.6648)
>> (-128.55247,0)
>> (-37.20473,64.44066)
>> ""
>> "after calling"
>> (-22.32306,38.6648)
>> (-128.55247,0)
>> (-128.55247,0) [33] )

As you can see, the value of ap is the same as b after coming out of the 
macro.  I'm not sure whether showing the entire code is relevent (there is 
a lot of code and all the parameters in the macro have the value of what I 
passed).  I can try to reproduce this issue with less code, but has anyone 
seen this problem before?

Thanks,
Yasir


More information about the metapost mailing list