array questions..

Ken Ray kray at sonsothunder.com
Tue Oct 15 13:35:01 CDT 2002


>   Is tehre a way to do "slice" or "slice-like" assignment to arrays (as in
> Perl)?  Can I say 'put [5,3,4,2] into z[4..7]' where z in an array?  Or
> just 'put [1,2,5,4,6,7] into z / put [1,4,5,6] after z'.  (Would that last
> one put them in as new elements?

Not with a single command AFAIK.

>   Also kind of related, can procedures return multiple values like in Perl
> (without using hashs).  Something like:
>
> function sumAndDifference(x y)
>   return (x+y), (x-y)
> end sumAndDifference
>
> -- main program
>
> put 0 into sum
> put sumAndDifference(6,5) into sum,diff
> put sum && diff
> -- gives "11 1

Not exactly. Handlers can only return a single value, although you can use
"pass by reference" mode of providing parameters to get what you need, as
in:

function sumAndDifference @x, at y
    put x into xVal -- need this to make sure x doesn't change
    put (xVal+y) into x  -- if you didn't have xVal, x would change to be 11
    put (xVal-y) into y
end sumAndDifference

put 0 into sum
put 6 into x
put 5 into y
get sumAndDifference(x,y)
put x && y
-- gives "11 1"

Hope this helps,

Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/




More information about the use-livecode mailing list