Using '@' to mark pass-by-reference (was Re: synonyms)
Bob Sneidar
bobsneidar at iotecdigital.com
Fri Aug 18 11:18:32 EDT 2017
That actually is a great explanation which solves a mystery I've often wondnered about, which is how a handler with a different variable name can contain the *actual* original variable. I thought the engine actually created a new variable and copied the incoming value to it, and then reversed this operation on return. Aliasing makes perfect sense.
Bob S
> On Aug 18, 2017, at 08:13 , Mark Waddingham via use-livecode <use-livecode at lists.runrev.com> wrote:
>
> In fact, what is happening is aliasing of variables:
>
> myHandler @tFoo -- when tFoo is passed to myHandler, xFoo1 in myHandler is aliased to tFoo
>
> command myHandler @xFoo1 -- xFoo1 as a variable does not exist, it is an alias to the calling var
> myOtherHandler @xFoo -- xFoo *is* tFoo, we are passing by-ref again so use @ which 'passes the alias on'
> end myHandler
>
> command myOtherHandler @xFoo2 -- xFoo2 as a variable does not exist, it is an alias to the calling var
> answer xFoo2 -- xFoo2 *is* tFoo
> end myOtherHandler
>
> Perhaps I'm not explaining this very well - or there is something I'm missing...
>
> Warmest Regards,
>
> Mark.
>
> --
> Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
> LiveCode: Everyone can create apps
More information about the use-livecode
mailing list