Array key paths

Peter Haworth pete at lcsql.com
Fri Nov 22 14:27:47 EST 2013


I'm not that familiar with the split command but doesn't it create a
numerically keyed array (starting at 1) when you specify just the primary
delimiter?  I think your split command would create:

s[1] containing "bob"
s[2] containing "age"

If so, you're back to numeric keys in the path key array

Pete
lcSQL Software <http://www.lcsql.com>


On Fri, Nov 22, 2013 at 9:38 AM, Richard Gaskin
<ambassador at fourthworld.com>wrote:

> Peter Haworth wrote:
>
>  On Fri, Nov 22, 2013 at 7:17 AM, Richard Gaskin wrote:
>>
>>  In my brief experiments it seems the path key array works like any other
>>> array, in that it's an associative array so that it makes no difference
>>> whether the key is numeric or a string, since the under-the-hood
>>> representation is still a string.
>>>
>>> Given this, Mark's 3) above is something I'm not seeing.
>>>
>>> What am I not understanding?
>>>
>>
>> I seem to remember getting an error if the keys of path key were not
>> integers.  Are you saying you've made it work with non-integer keys?
>>
>
> This test seems to work:
>
> Script of one button to load the array:
>
> on mouseUp
>    global gA
>    put "bob" into gA["bob"]
>    put "44" into gA["bob"]["age"]
>    put "ted" into gA["ted"]
>    put "48" into gA["ted"]["age"]
> end mouseUp
>
> Script of a second button to split a key and use it to retrieve a value:
>
> on mouseUp
>    global gA
>    put fld "key" into s
>    split s by comma
>    put gA[s] into fld "r"
>    put the result
> end mouseUp
>
>
> There are two fields - the one named "key" has:
>
> bob,age
>
> ...and when I click the second button the field named "r" shows:
>
> 44
>
> Nothing shows in the Message Box, so presumably there was no error.
>
> This is what I would expect, since associative arrays usually have no way
> to distinguish between numeric and non-numeric keys, since all of them are
> treated as strings when they go through the hash to assign their buckets.
>
>
> --
>  Richard Gaskin
>  Fourth World
>  LiveCode training and consulting: http://www.fourthworld.com
>  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
>  Follow me on Twitter:  http://twitter.com/FourthWorldSys
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list