Array keys oddity?

Bernard Devlin bdrunrev at gmail.com
Sun Jun 7 06:00:57 EDT 2009


Part of the problem is that we refer to these containers in Rev as
"arrays".  Really what Rev has is a container that is more
appropriately referred to as a "dictionary".  It is commonplace in
other languages to expect that a dictionary object will return the
keys in an unsorted (and generally unpredictable order).

Dictionary objects have unique keys.  That is why in Rev we can
simulate arrays when numbers are used as the keys.  Other languages
also have "true" array containers that are only indexed numerically,
and will return their contents in the same predictable, stable order
all the time.

I'm not saying that this is a deficiency in Rev.  It's quite handy to
have the same container functioning as either an array or a
dictionary.  Personally, I always refer to these containers as dicts
in my own code.  That way I never mislead myself into thinking they
are arrays.  Although I'm still sometimes vexed when I look at an
"array" in the debugger and find the keys are sorted alphabetically
rather than numerically.

Bernard


On Fri, Jun 5, 2009 at 5:45 PM, <DunbarX at aol.com> wrote:
> Jacques.
>
> Thanks. Good to know it was only ignorance, not sloppiness.
>
> Craig
>
> In a message dated 6/5/09 11:56:06 AM, jacque at hyperactivesw.com writes:
>
>
>> The keys of an array are returned according to an internal engine hash
>> order. They will virtually never be in the same order in which they were
>> created. If order is important, you need to get the keys and then sort
>> them.
>>
>



More information about the use-livecode mailing list