Arrays in Rev

Alex Tweedly alex at
Sat Dec 11 09:17:54 EST 2004

At 00:50 11/12/2004 -0600, Ken Ray wrote:
>For more information, we had a long thread about arrays in Rev back in July
>(I put out a small "dissertation" on arrays at that time:

Thank you - I found it useful then (I was new to Rev at the time), and 
found it even more useful to go back and re-read it now, with a slightly 
better understanding of the different ways to do things in Rev. It should, 
IMHO, be in a FAQ or Wiki or some such place, not just in the mail archives.

(Wasn't someone starting a community FAQ ? )

I do have one question about it ....

>   put "1,Troy,Ken,Richard"&cr&"2,Kevin,Jan,Judy" into myList
>   split myList by CR and ","
>   put myList[2] into tempArray
>   --> Kevin,Jan,Judy
>   split tempArray by ","
>   put tempArray[1]
>   --> Kevin
>But note that this is NOT usually something you'd do in Rev... Director is
>designed to be able to make arrays of arrays, and although Rev can simulate
>this, it is not the most efficient, nor is it the best approach. One reason
>is that if you'll notice, I had to add line numbers before each line in
>myList so that when I used 'split' I could reference the array by number.
>Why? Because remember that no matter what it may appear to be, Rev uses
>associative arrays ONLY - myList[1] is NOT numeric... it is creating a
>*string* called "1" that is associated with the value that you give it.

I don't get it. You need the second "split" to split up the entries Kevin 
and Jan and Judy - so why use the second delimiter in the first split. 
Couldn't you just do ....

   put "Troy,Ken,Richard"&cr&"Kevin,Jan,Judy" into myList   -- NB no numbers !!
   split myList by CR     -- note - no second delimiter
   put myList[2] into tempArray
   --> Kevin,Jan,Judy
   split tempArray by ","
   put tempArray[1]
   --> Kevin

>In any event, we really do need better array manipulation for
>multidimensional arrays (or simulated ones). Personally, I'd rather have the
>real thing if we can get it; if not, I'd accept simulated ones as long as we
>have accessor functions to get at the embeded data more easily.

I agree - though I'm not sure it's possible to get a good enough simulation 
to satisfy what I'd like.
I want to be able to do things like
    put "here's the string" into myArray1["asdf"]
    put myArray1 into myArray2[3]
    put myArray2[3] into tVar

and have tVar now be an array.

While I'm talking about what I'd like regarding arrays, I'd love to have 
the multi-assignment form of a repeat structure as in PHP or Python. I know 
it doesn't, strictly speaking, add functionality, but I think it's a huge 
gain in readability. What I mean is to be able to say something like

   repeat for each keyvalue  K,V in myArray
     -- K takes each key in turn
     -- V takes the corresponding value from the array

so it's equivalent to
    repeat for each line K in the keys of myArray
        put myArray[K] into V
but is (IMHO) much more readable (and probably a bit more efficient).

-- Alex.

More information about the use-livecode mailing list