ABC of arrays

Graham Samuel livfoss at mac.com
Wed Apr 1 16:48:17 EDT 2015


Richard, forgive me for just extracting a bit of your interesting mail. I see that the real issue is with the idea of sub-arrays, which have their own sets of keys. You emphatically do not get a list of all the keys of an array with subarrays in it from the ‘put the keys’ action. I modified your handler in just one respect: 

on mouseUp
   put "1" into tA[1]
   put "2.1" into tA[2][1]
   put "2.2" into tA[2]["surprise me, Jean"]
   put 3 into tA[3]
   put the keys of tA
   put the keys of tA
end mouseUp

and I got

3
1
2

So, the “surprise” key wasn’t represented - because it’s a sub-array of tA[2], I suppose. In fact your example is odd in a way, since you use the key [1] for example in the primary array and again in the sub array. These are different keys that just happen to use the same value. This makes my head hurt a bit.

So, following on another mail I just sent, I think people can get confused by sub-arrays and what ‘the keys’ actually looks at. More examples needed in the docs, perhaps.

Hope this is not seen as wilful misunderstanding - it’s not meant to be!

Graham

> On 1 Apr 2015, at 22:32, Richard Gaskin <ambassador at fourthworld.com> wrote:
> 
> 
> The "keys" should return a list of all keys, even when the value of any of them may be another array.
> 
> This is consistent with what you found:  your array gGeneralArray contain one element, and that element is another array.  You can also query the keys for the sub-array and obtain its keys, as you did.
> 
> Consider this much simpler example in which we have three keys, two of which have values that are not arrays and one of which has an array for its value:
> 
> on mouseUp
>   put "1" into tA[1]
>   put "2.1" into tA[2][1]
>   put "2.2" into tA[2][2]
>   put 3 into tA[3]
>   put the keys of tA
> end mouseUp
> 
> In my Message Box I get:
> 
> 3
> 1
> 2
> 
> ...showing that all keys are accounted for, even tA[2] where the value is another array.




More information about the use-livecode mailing list