Thanks very much for the explanation Mark.

Regards

Peter

> On 21 Sep 2015, at 16:52, Mark Waddingham <m...@livecode.com> wrote:
> 
> Like numbers and strings, arrays are values so they are always (notionally) 
> copied whenever they move between locations.
> 
> In 7+ this copying is deferred until needed (copy-on-write), prior to 7 they 
> are copied immediately.
> 
> So, yes, you can pass arrays around without worry.
> 
> Mark.
> 
> Sent from my iPhone
> 
>> On 21 Sep 2015, at 03:28, Peter W A Wood <peterwaw...@gmail.com> wrote:
>> 
>> I understand that arrays are passed by reference in LiveCode not by value. I 
>> assume that is also that case if you return an array from a function (i.e. 
>> the reference to the array is returned not its content). When I tried to 
>> return an array from a function, I found that not only you can do so but 
>> multiple calls of the function provide different arrays. As the array being 
>> returned from the function is local to the function, I’m guessing that 
>> LiveCode is creating a new local array for each function call and returning 
>> a reference to the local variable.
>> 
>> Here is the code that I ran under LiveCode Server:
>> 
>> function returnArray
>> local a
>> put 1 into a[1]
>> return a
>> end returnArray
>> 
>> put returnArray() into b
>> put b[1] & return                —> prints 1
>> 
>> put returnArray() into c
>> put c[1] & return                —> prints 1               
>> 
>> put 3 into c[1]
>> 
>> put b[1] & return                —> prints 1
>> put c[1] & return                —> prints 2
>> 
>> Is it safe to use such a technique or will the reference to the array become 
>> invalid at some stage?
>> 
>> Peter
>> 
>> 
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription 
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to