associative arrays

Scott Raney raney at metacard.com
Fri Dec 13 18:40:01 EST 2002


On Fri, 13 Dec 2002 Dar Scott <dsc at swcp.com> wrote:

> On Friday, December 13, 2002, at 02:47 AM, Robert Brenstein wrote:
> 
> > However, I need to pass it as an argument to a function that is 
> > dynamically defined and executed through do.
> >
> > put webArg into fName -- let's say webArg = somfunction
> >
> > do "get" && fName & "(" & myArray & ")"

This is the wrong syntax: you're passing the *value* of myArray in
this case, which is going to be empty if it's really an array.  I
think you wanted something like:
do "get" && fName & "(myArray)"

> > function somfunction myArray
> > return myArray[key]
> > end somfunction
> >
> > In somfunction, the associative array give empty values for key and 
> > array elements.
> 
> I have seen other limitations.  I can return an array from a function 
> and pass an array as a parameter but not both in the same expression as 
> in somFunction(buildArray()).

This is because you can only pass arrays using *variables*, not as the
return value of a function call.  In C/C++/Java, trying to do the
above where "someFunction" takes a reference would generate a syntax
error.  MC/RR, being an untyped language, just silently takes the
scalar value (which in this case will be empty) if it can't find a
variable when it gets to the called function.  You can work around
this by breaking it into two steps:
get buildArray()
get someFunction(it)

> Dar Scott
> (a Revolution user sitting in the back row)

Ah, the infamous "voice from the back of the room" ;-)
  Regards,
    Scott

********************************************************
Scott Raney  raney at metacard.com  http://www.metacard.com
MetaCard: You know, there's an easier way to do that...




More information about the metacard mailing list