> On 16 Mar 2020, at 10:23, Taco Hoekwater <t...@elvenkind.com> wrote:
> 
> 
> 
>> On 16 Mar 2020, at 10:10, Taco Hoekwater <t...@elvenkind.com> wrote:
>> 
>> 
>> 
>>> On 16 Mar 2020, at 09:53, Gerben Wierda <gerben.wie...@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.

Coffee! Thanks anyway, Taco, your help is really appreciated.

> 
>  vardef Foo(text y) = 
>    scantokens(y&":=5”);
>  enddef;
>  Foo("x");
> 
> This would work, but that is weird.

Which is somewhat intuitive to parse as a human. I understand it as that after 
the last statement x has the value 5.

> 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;
>  enddef;
>  numeric foo[]; 
>  foo[1] = 6;
>  Foo(1,foo);

This was initially complete gobbledegook to me. But I now think that after the 
last statement foo[1] equals 5. Very weird/counterintuitive that y[a] := 5 
works here without the use of scantokens. The first one is less weird to me 
because scantokens actually calls the METAPOST parser on a string as if read 
from a file.

> 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.

I actually have that book and did a try small bit of METAFONT long, long ago to 
create a logo in it. Maybe that explains things better. (Unearthing the book 
for later use…)

> As you can clearly see, even experienced users are likely to make mistakes.

The main problem with all of this (ConTeXt, METAPOST, etc.) remains the 
learning curve and the lack of good and up-to-date educational materials. I.e. 
the METAPOST manual is terse, probably because it relies on people 
understanding the background that is in the METAFONT book.

And, if one is used to thinking in terms of functional programming, all that 
‘expansion’ stuff (‘replacement’  programming?) is very counterintuitive for 
me. Lua then adds a functional model to the mix (or I think it does). Very hard 
to make progress. I learned Python in a day and produced a complex program in a 
matter of weeks. This is far less easy. And not being able so far to see what 
intermediate results lea to errors adds to the slow going.

I.e., the whole chapter on vardef in the METAFONT book is 

G

> 
> 
> Best wishes,
> Taco
> 
> 
> 
> 
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the 
> Wiki!
> 
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to