array info request (new thread)

Dennis Brown see3d at writeme.com
Mon Jul 25 13:22:17 EDT 2005


On Jul 25, 2005, at 12:00 PM, keith wrote:
> Sometime around 25/7/05 (at 01:19 -0400) Thomas McGrath III said:
>
>
>> I always learn best by example.
>>
>
> Absolutely!
> Speaking of learning by example (or any other method, I'm not  
> fussy! ;-) is there anything around that could help me get my head  
> around arrays? Some kind of simple guide that doesn't start out at  
> too high a level? Gotta start sometime! :-)


Keith,

It also took ma a bit of time to understand arrays.  It turns out to  
be rather simple.
Please let me practice a bit with some ideas I have about how to  
explain arrays in simple terms.

An Array element is simply a variable with two names.  The family  
name like Jones and the secondary name Jones["David"].
Now each time a new Jones kid is born, we can create a new entry for  
his birthday put "2005,July,25," into Jones["John"]
Arrays may look like they are complex multidimensional constructs,  
but it is a lie --they are simple one dimensional variables.
Array[key] and Array[key1,key2,key3] are both actually flat.  Array 
["1,2,3"] is the same as Array[1,2,3].
The keys of Array is a list of all the combinations of keys that have  
a data element stored.
An Array key can be any text.  A multidimensional array key is just a  
text version of all the keys combined key1&","&key2&","&key3
Because arrays are variables they lose there contents the same as  
other variables.

One kind of array will cam retain its values.  These are called  
custom property sets.  See Dan's scripting conference for some more  
details about these.
The limitation of using a custom property set is that you are limited  
to a single key in the [key].  However, as I have just shown, that is  
not really much of a limitation because you can create your own  
multiple key by combining keys like CustomPropertySetArray 
[key1&&key2&&key3].

The advantage of arrays over creating a bunch of variable names  
(e.g.,  put "2005,July,25," into (Jones&John)), is that you can't do  
that without a 'do' command which is slow and is also cumbersome to  
write.  With an array you can build the key name the same way you can  
build any text or number.  In fact you could have a single generic  
array that is used just for the purpose of making up variable names  
on the fly:  allMyVariables["someVariableName"], but this is an  
extreme example just to make a point.

Getting the keys of an array make it clear what is going on.

There is more you can do with special commands like split and combine  
arrays.

Some commands only work with arrays where all the elements must be  
numbers --like Sum, Average, Median, Min, Max, StandardDiviation.   
The array is just a proxy for a list of numbers.

Other commands only work with arrays that only have a two sequential  
numbers as two keys (x,y) and all the elements must be numbers --like  
matrixMultiply and transpose.

I don't know if this was any help, but I would also like to improve  
my conceptualizing of Rev arrays.  Please ask more questions, or if  
anyone else has another slant on understanding arrays please  
contribute it to this thread.  Perhaps it can be used as the  
springboard to a scripting conference stack on arrays and lists.





More information about the use-livecode mailing list