ABC of arrays
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:
put "1" into tA
put "2.1" into tA
put "2.2" into tA["surprise me, Jean"]
put 3 into tA
put the keys of tA
put the keys of tA
and I got
So, the “surprise” key wasn’t represented - because it’s a sub-array of tA, I suppose. In fact your example is odd in a way, since you use the key  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!
> 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
> put "2.1" into tA
> put "2.2" into tA
> put 3 into tA
> put the keys of tA
> end mouseUp
> In my Message Box I get:
> ...showing that all keys are accounted for, even tA where the value is another array.
More information about the Use-livecode