Passing an array to a function/handler
Dar Scott
dsc at swcp.com
Wed Jun 11 20:06:00 EDT 2003
On Wednesday, June 11, 2003, at 05:27 PM, Huisingh, Larry R wrote:
> I can't tell from the docs...Can you pass an array to a function (or
> handler)?
Yes, but arrays do not have full value semantics.
You can pass an array as a parameter.
You can return an array as the "value" of a function, but that cannot
be directly a parameter to another function or handler and it cannot be
[ ]'d. You cannot create array expressions.
This means you can use an array to represent interesting data, but the
fact that it is an array cannot be hidden. (Because of that, you can
feel free to use reference variables as parameters, should you work
with very large arrays, even when you don't modify the variable--you
can't have an array expression as a parameter, anyway.)
Try this:
function fetch e, k
return e[k]
end fetch
function makeA
local x
put "abc" into x["a"]
put "a" into x["b"]
return x
end makeA
on mouseUp
local y
put "eee" into y["v"]
put fetch(y,"v") & LF into field "Report"
put fetch(makeA(),"a") & LF after field "Report"
put makeA() into y
put fetch(y,"b") & LF after field "Report"
end mouseUp
This produces this:
eee
a
It does not produce this:
eee
abc
a
Also, arrays will be empty whenever a string conversion occurs. This
includes "send".
Dar Scott
Revolution Lurker who needs arrays. Or, at least, a bonus.
More information about the metacard
mailing list