ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	Taco Hoekwater <taco@elvenkind.com>
Subject: Re: METAPOST vardef returning multiple and non-numeric types as a single answer?
Date: Mon, 16 Mar 2020 10:38:35 +0100	[thread overview]
Message-ID: <30920eea-ae02-142c-7c07-8c28534e5951@xs4all.nl> (raw)
In-Reply-To: <23515AF0-D380-4D3D-BC62-078A179ED65F@elvenkind.com>

On 3/16/2020 10:23 AM, Taco Hoekwater wrote:
> 
> 
>> On 16 Mar 2020, at 10:10, Taco Hoekwater <taco@elvenkind.com> wrote:
>>
>>
>>
>>> On 16 Mar 2020, at 09:53, Gerben Wierda <gerben.wierda@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) =
>      scantokens(y&":=5”);
>    enddef;
>    Foo("x");
> 
> 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;
>    enddef;
>    numeric foo[];
>    foo[1] = 6;
>    Foo(1,foo);
> 
> 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.
it's the mixture of delayed parsing and expansion and ... no other 
language like that i guess (which at the same time is its charm)

passing "text y" is (i think) not that that far from the scantokens 
(running over already tokenized vs running over a string while 
tokenizing it ... but these input models (are we in scanning file input, 
string input, tokenlist) can be kind of confusing

that said, after muy share of mp programming i would not have thought 
about the text y as pass by reference, also because it's only true for 
these pseudo arrays (maybe suffixes also work)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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	other threads:[~2020-03-16  9:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-15 10:22 Gerben Wierda
2020-03-16  8:31 ` Taco Hoekwater
2020-03-16  8:53   ` Gerben Wierda
2020-03-16  9:10     ` Taco Hoekwater
2020-03-16  9:23       ` Taco Hoekwater
2020-03-16  9:38         ` Hans Hagen [this message]
2020-03-16  9:52           ` Gerben Wierda
2020-03-16  9:48         ` Gerben Wierda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=30920eea-ae02-142c-7c07-8c28534e5951@xs4all.nl \
    --to=j.hagen@xs4all.nl \
    --cc=ntg-context@ntg.nl \
    --cc=taco@elvenkind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).