Strange hang

Alex Tweedly alex at tweedly.net
Tue Jan 15 07:34:33 EST 2013


On 15/01/2013 06:29, Peter Haworth wrote:
> I believe what you cannot do is pass an array element by reference. So your
> faddnum function cannot be declared as:
>
> function faddnum @pnum

That's right.
> Not that you would want to do that in a function but you might be tempted
> to make it a command defined that way.
I'm not so sure that you wouldn't want to do it with a function :-)

There are two reasons to make a parameter be "passed by reference".

1. to allow it to be modified within the function/handler
2. to save the cost of copying the variable (e.g. if it's a very large 
array or string).

Either of these could apply to functions just as easily as to handlers. 
It's common "good practice" to avoid side-effects (i.e. modification of 
by-ref parameters) in functions - but if the main purpose is to modify 
the parameter, and the returned value from the function is just a simple 
way to indicate success/failure, then it's arguably a very reasonable 
coding practice.

And the cost saving of not copying can be significant - though ONLY IF 
the variable content may be VERY large (i.e. Gbytes or many tens of 
Mbytes of string or nested array), and/or the function may be called 
very often.

-- Alex.






More information about the Use-livecode mailing list