Can we return a path
or picture
from a vardef
macros? And how to call the return value? Google said "the last statement has no semicolon; its value is returned by the function". My purpose is to repeat using the path or picture. Followed is a small code. But it failed. Maybe I misunderstood something. Please note that the returned path or picture might not need to be drawn out. It might be used to help to construct something else, e.g., help to find intersection point.
vardef foo (expr from, to) =
path p;
p = from -- to
enddef;
beginfig(1)
path p;
pair A, B;
A = (0,0);
B = (1,1);
p = foo (A, B);
draw p;
endfig;
path p;
inside your vardef will remove the value ofp
outside it. (b) there is no "residue" from an equation, so there's nothing to return from the final statement of your vardef. So MP returnsvacuous
, and I guess you got an error sayingEquation cannot be performed (path=vacuous)
.vacuous
.