Using '@' to mark pass-by-reference (was Re: synonyms)

Mark Waddingham mark at livecode.com
Fri Aug 18 11:13:34 EDT 2017


On 2017-08-18 15:53, Mike Kerner via use-livecode wrote:
> I understand the difference.  I'm just trying to help with the mental
> arithmetic.  I, and others, I'm sure, will constantly forget where the 
> "@"
> goes, for instance.

Okay so - the question to ask is - what would make you forget where to 
put the "@"?

In this case, if you want a by-ref parameter you have to put '@' before 
it in the signature, the proposal is to allow '@' to also be placed 
before the argument in a handler call for by-ref parameters... So it is 
entirely symmetric:

   command myHandler @xFoo
   end myHandler

   myHandler @tFoo

There is no 'de-referencing' operation as by-ref parameters implicitly 
de-reference on use - indeed, there's no need to have a de-reference 
operation because there is no such thing as a 'reference' which can be 
'put into' a variable (that would be general references - which this 
isn't about).

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