[NTG-context] METAPOST vardef returning multiple and non-numeric types as a single answer?

Taco Hoekwater taco at elvenkind.com
Mon Mar 16 10:23:07 CET 2020

> On 16 Mar 2020, at 10:10, Taco Hoekwater <taco at elvenkind.com> wrote:
>> On 16 Mar 2020, at 09:53, Gerben Wierda <gerben.wierda at rna.nl> wrote:
>> Hola! So, the arguments passed to macros are by reference and not by value? I could have known of course, they are simple expansions, but I’d like to be sure. IfI assign to a variable inside a vardef macro and that variable is not ’save’d I’m changing the original?
> Yes. (A simple test would have confirmed that)

Oops, sorry, no! I was wrong on that… it must be too early for me.

  vardef Foo(text y) = 

This would work, but that is weird. This also works, and that is why
I had the erroneous memory that it would work always:

  vardef Foo(expr a)(text y) = 
    y[a] := 5;
  numeric foo[]; 
  foo[1] = 6;

or you could use global variables, of course.

Main point: Metapost is not an easy language to grasp. If you want to
really understand how it works, you should study the Metafont book by DEK.
As you can clearly see, even experienced users are likely to make mistakes.

Best wishes,

More information about the ntg-context mailing list