ABC of arrays

Bob Sneidar bobsneidar at iotecdigital.com
Mon Apr 20 16:38:36 EDT 2015


Not sure what this means, but an array (or element of an array) can contain one key that is a value, and another key that contains an array. In this context I do not see how this statement that a box (element of an array) can contain another array or a value but not both. It’s kind of like saying a parking space can contain either a car or a rider on a bicycle, but not both.

It may help to think of an array like a spreadsheet. Each cell has a name, and inside the cell, a value. A workbook is kind lf like a multidimensional array, where you can have multiple “arrays” in a single object (the file itself). What would make the analogy complete is if a cell itself could contain another spreadsheet.

A really good analogy of a Livecode style array is the filing system on your hard drive. Inside the hard drive (array) you can have a file (element) that contains data, or a folder (element containing another array) that can also contain files or other folders and so on. Each of those objects has a name (key) that identifies it. MyHD/MyFiles/LCDocs/Test.lc is a kind of array reference. In an LC array it would look like: MyHD [myFiles] [LCDocs] Test.lc.

What confuses people (and what confused me at first) was that people naturally expect one dimension of an array to contain only values or only other arrays. That would be a little like the original Mac file system where technically there were only files, and folders were really just markers on the file. It wasn’t a truly heirarchical file system.

One other confusing thing is that if you check a variable containing an array for empty it will return true. You have the check to see if the variable is an array to see if there is an array in it.

HTH
Bob S


On Apr 1, 2015, at 17:58 , Ralph DiMola <rdimola at evergreeninfo.net<mailto:rdimola at evergreeninfo.net>> wrote:

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<mailto:rdimola at evergreeninfo.net>



More information about the use-livecode mailing list