ABC of arrays
rdimola at evergreeninfo.net
Wed Apr 1 20:58:09 EDT 2015
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.
Evergreen Information Services
rdimola at evergreeninfo.net
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:
> 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"
>> <metadata />
>> 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
>> 5. I discussed this on the use-list, and Mike Bonner suggested
>>> put the keys of gGeneralArray["gpx”] and you'll get the next level
>>> of keys.
>> 6. I did that and got
>> 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!
>> On 1 Apr 2015, at 18:27, Richard Gaskin <ambassador at fourthworld.com>
>>> Graham Samuel wrote:
>>>> And some things are just wrong: for example the very simple
>>>> 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:
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the Use-livecode