ABC of arrays

Ralph DiMola rdimola at evergreeninfo.net
Wed Apr 1 20:58:09 EDT 2015


Mike,

Well explained...

Just when I learned the power of LC array the fact that a box could only contain a data item OR other boxes is what bit me. I actually coded up a mini storm and it wasn't until I start testing that I figured this out. At the time I couldn't think of a reason why LC couldn't be changed so a box could contain a data item AND other boxes. Later on I realized that it would break old code. Other than that it would be an asset to the LC array.


Ralph DiMola
IT Director
Evergreen Information Services
rdimola at evergreeninfo.net


-----Original Message-----
From: use-livecode [mailto:use-livecode-bounces at lists.runrev.com] On Behalf Of Mike Bonner
Sent: Wednesday, April 01, 2015 7:40 PM
To: How to use LiveCode
Subject: Re: ABC of arrays

I'm one who uses visualization to get a handle on things like arrays.  For me, arrays are just a bunch of nested boxes.  And a box can contain other boxes, or a dataitem, but not both.

So if you get the keys of myArray you've just looked into the first box to see whats there. If there are no keys in myArray of course, its not array, and must be empty, or contain a data item.
If there are keys, those are just other boxes, and you must specifically open each box to see whats inside it. the keys of myArray["box1"] might contain a data item, or more boxes. (and since square brackets are used, it actually reinforces my mental picture of little boxes all the same)

On Wed, Apr 1, 2015 at 3:19 PM, Michael Doub <mikedoub at gmail.com> wrote:

> Graham,
>
> I think one of the things that is confusing you as you are trying to 
> learn arrays is the fact that you are looking at output created by
> ConvertXMLToArray.   ConvertXMLToArray is working as designed, but it just
> happens to create key in a syntax that looks like a livecode array
> reference.    LiveCode keys are just strings, so ConvertXMLToArray is
> adding a open bracket, a counter, and a close bracket when it sees 
> multiples of a xml tag, to make it unique within the array.
>
> This makes perfect sense technically but I can see where it could 
> really confuse someone trying to figure out livecode arrays.
>
> -= Mike
>
>
>
>
> On 4/1/15 3:48 PM, Graham Samuel wrote:
>
>> Well, Richard, I am always very willing to believe that I’ve 
>> misunderstood something, but this is what happened (this material is 
>> extracted from conversations I had on this list in the middle of March).
>>
>> 1. I had an XML file - it was actually a .gpx file, which shows a 
>> geographical route as a series of waypoints. The ‘top level’ of this 
>> structure is ‘gpx’. I mean the first three lines are (watch for wordwrap):
>>
>> <?xml version="1.0" encoding="UTF-8"?> <gpx 
>> xmlns="http://www.topografix.com/GPX/1/1" creator="Geolives"
>> version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="http://www.topografix.com/GPX/1/1
>> http://www.topografix.com/GPX/1/1/gpx.xsd">
>>    <metadata />
>>    <trk>
>>
>> 2. I converted it to an array using the function ConvertXMLToArray, 
>> by Trevor deVore - from Mike Doub’s Master Library.
>>
>> 3. I put the result into an array called ‘gGeneralArray’ - I can see 
>> this in the IDE as a nested structure.
>>
>> 4. I executed
>>
>>    put the keys of gGeneralArray
>>
>> in the message box, and got the result
>>
>>   gpx
>>
>> 5. I discussed this on the use-list, and Mike Bonner suggested
>>
>>  try
>>> put the keys of gGeneralArray["gpx”] and you'll get the next level 
>>> of keys.
>>>
>> 6. I did that and got
>>
>> wpt[1]
>> trk
>> @attributes
>> wpt[4]
>> wpt[2]
>> metadata
>> wpt[3]
>>
>> I just did this all again to prove to myself that I hadn’t made an 
>> obvious error.I am definitely only dealing with one array, so I can’t 
>> explain this, and the LC dictionary certainly doesn’t help.
>>
>> Tell me where I went wrong!
>>
>> Graham
>>
>>  On 1 Apr 2015, at 18:27, Richard Gaskin <ambassador at fourthworld.com>
>>> wrote:
>>>
>>> Graham Samuel wrote:
>>>
>>>> And some things are just wrong: for example the very simple 
>>>> statement
>>>>
>>>> put the keys of myArray
>>>>
>>>> may or may not list all the keys, or it may.  I have never 
>>>> understood this, especially as the Dictionary doesn’t discuss such ambiguities.
>>>>
>>> The Dictionary doesn't describe that because it should never happen.
>>>
>>> Under what circumstances would "the keys" not returns the keys?
>>>
>>> FWIW, I've only seen "the keys" return all keys in every version of 
>>> LC/MC I've ever used.
>>>
>> _______________________________________________
>> 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
>>
>
>
> _______________________________________________
> 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
>
_______________________________________________
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