Arrays in LC [was: Re: [TAO] value() to obtain pointer functionality]
Trevor DeVore
lists at mangomultimedia.com
Fri Aug 29 07:59:43 EDT 2014
On Wed, Aug 27, 2014 at 11:59 AM, Richard Gaskin <ambassador at fourthworld.com
> wrote:
>
> All keys in associative arrays are strings, and currently LC only supports
> associative arrays. The string may consist of numerals only, but it's
> still a string.
>
> It would seem that Trevor rebuilds the array on deletes. It would be
> interesting to hear more about how he does this if he reads this message
> and has time to reply.
>
> Or one of us could dive into the DG code and find it. Either way, I
> suspect it's iterating over the collection.
If I have an array which should be ordered (numerically indexed) AND the
order of elements in the array can change then I use a key in the array
that stores the sequence of elements in the array.
For example:
put "Bob" into thePeopleA["data"][1]["name"]
put "Richard" into thePeopleA["data"][2]["name"]
put "Trevor" into thePeopleA["data"][3]["name"]
put "1,2,3" into thePeopleA["ids"]
When I iterate over the array I loop through each item in thePeopleA["ids"]
If I need to reorder/delete/add then I update the "ids" key. For example,
if I wanted "Richard" to be first in the list then I would change "ids" to
this:
put "2,1,3" into thePeopleA["ids"]
For arrays that aren't meant to be modified I don't bother with the "ids"
property as I know I can just loop from 1 to the number of elements of
thePeopleA.
--
Trevor DeVore
ScreenSteps
www.screensteps.com - www.clarify-it.com
More information about the use-livecode
mailing list