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

Reply via email to