Arrays in LC [was: Re: [TAO] value() to obtain pointer functionality]

Peter Haworth pete at lcsql.com
Tue Aug 19 19:58:30 EDT 2014


Hi Graham, See below for what I can contribute to this

Pete
lcSQL Software <http://www.lcsql.com>
Home of lcStackBrowser <http://www.lcsql.com/lcstackbrowser.html> and
SQLiteAdmin <http://www.lcsql.com/sqliteadmin.html>


On Tue, Aug 19, 2014 at 1:44 PM, Graham Samuel
>
>
>
> In LC, I think (but I am fuzzy, which is why I'm writing this), the
> 'keys', i.e. the designators of each element, like 1, 2 etc in my old
> system, can be any character string, including of course the cardinal
> numbers as above, or the ordinal numbers for that matter, or something
> completely arbitrary like say the names of stations on the London Tube map.
> This must mean that, it seems to me, that there is no longer any implied
> order: I mean AA["Oxford Circus"] is neither before nor after
> AA["Victoria"]. I suppose that if some sense of order is required, then one
> simply has to choose inherently ordered keys, like letters of the alphabet,
> cardinal numbers etc. Can someone confirm this?
>

Correct.  If you want to get the elements of an array in order, then:

put the keys of AA into tKeys
sort tKeys -- possibly with numeric if they keys are numeric
repeat for each line rKey in tKeys
   do stuff
next repeat

I guess if you knew the keys were numeric you could:

repeat with x=1 to the number of lines in the keys of AA
  do stuff
end repeat

>
>
> The other thing I think I understand is that an array element (the
> contents of AA["Victoria"]) can be anything, from empty to an entire stack,
> and taking in other arrays, which gives the possibility of
> multi-dimensional arrays, doesn't it? Again I am fuzzy: suppose we have a
> superset called, I dunno, 'Metros of the world', or 'MoW' for short. So an
> element of this can be
>
> MoW["London Tube"["Oxford Circus"]]
>
>  can it? Or is that meaningless, and one has to write
>
> MoW["London Tube] ["Oxford Circus"]
>

The second of your examples is how you have to do it in LC.  And of course,
the "Oxford Circus" key could have its own subkeys too.

Basically each array key can either have a value stored in it or can have
subkeys attached to it, but not both.

For example MoW["London Tube"]["Oxford Circus"] could have a value of
"Central" or you could have MoW["London Tube"]["Oxford  Circus"]["Line"]
key with the value "Central" but not both.

You can put an array into another array but it's really the same as putting
the keys/values of that array into the target array individually.

For example, lets say you have ArrayA[1] with a value of "ABC" and
ArrayB[1] with a value of "DEF" and ArrayB[2] with a value of "GHI", if you
put arrayB into ArrayA[2] you'll end up with

ArrayA[1] = "ABC"
ArrayA[2][1]= "DEF"
ArrayA[2][2]="GHI"


>
> A further issue to me is the operations that are allowed on entire arrays
> in LC - I note the existence of 'split' and 'combine'. Is that it? What
> happens when you combine a multidimensional array?
>

combine and split only work on single dimensional arrays and some forms of
them can only be used on numerically keyed arrays.  Sure would be nice to
have a "recursive" keyword or something like that.

There's also the matrixMultiply command.  It only works on
numerically-keyed, single dimension arrays.  Not sure why there isn't a
matrixAdd/Subtract/Divide/etc but there's no mention of them in the
dictionary.

And then there's the extents property which returns the lowest and highest
keys of a numerically-keyed array.

The dictionary also lists a transpose command but I honestly can;t figure
out what use it is and since it causes a runtime error when I've tried to
play with I haven't bothered to check it out.

Hope that helps



More information about the use-livecode mailing list