Re: ‘Super Sub’ multidimensional arrays

Richard Gaskin ambassador at fourthworld.com
Thu Mar 11 11:03:39 EST 2021


Sean Cole wrote:

 > Why is tArray[x,y,z] more useful/flexible but not better
 > than tArray[x][y][z]?

Is it?

Remember the definition of an array:  a collection of name-value pairs 
where the name can be any string up to 255 chars long, and the value can 
be any data, including another array.

With that in mind, this:

     tArray[x,y,z]

...is recognized a one-dimensional array.

It just happens to include commas in the key string.

An array using delimited strings as keys might be useful for parsing 
lists of those keys.

You could also parse the key strings with a custom delimiter:

     tArray[ x &tab& y &tab& z ]

Sometimes this may be useful for aggregate operations on an array, such 
as LC's matrixMultiply function which suggests the delimited-string 
form, or other operations where using filter on the key list may be 
helpful, e.g.:

     put the keys of tArray into tKeys
     filter tKeys with "4,*"

But you can't obtain any subarray using only delimited key strings, 
because there is none.

For that you would need a multidimensional array: tArray[x][y][z]

Depending on what you're doing, there may be cases where using delimited 
string keys in one dimension is useful in an array where other 
dimensions use simpler strings:

     tArray[a][x,y,z][b]

LiveCode is very flexible, giving us many options for structuring data 
according to the needs of the task at hand.  Which is "better" or "more 
useful" depends on the problem being solved.

-- 
Richard Gaskin
Fourth World Systems




More information about the use-livecode mailing list