Q on Accessing multi-dimension arrays.
Richard Gaskin
ambassador at fourthworld.com
Thu Apr 26 14:55:14 EDT 2018
Alex Tweedly wrote:
> I have a multi-dimension array, say created by
>
> put "answer" into tArray["firstkey"]["secondkey"]
>
> Is there some way or format to specify the array elements using the
> "path" of the keys, rather than each one at its own level) ?
>
> i.e. something like (but obviously not exactly)
>
> put tArray["firstkey,secondkey"]
>
> where each item/part of the key is interpreted s the next level in the
> multi-dimension.
You may be thinking of the matrixMultiply function, which requires each
array key to be a comma-separated pair of numbers. That was written
before LC had multidimensional arrays; not sure if it would have been
written that way if deeper arrays were available at the time.
All array keys in LC are strings. Whether a number, or a pair of
numbers with some punctuation included - all just a string.
It would be nice to be able to represent deep arrays with paths, though.
That's been a dream of mine for years, to be able to use XPath-like
functions on LC arrays.
But alas my best efforts at simulating that in script ultimately require
dynamic evaluation (do, value, etc.), where the speed loss adds up
quickly since this is most worth applying to large arrays.
And given that the engine doesn't currently prohibit "/" from being part
of an array key (only NULL is prohibited), I haven't bothered submitting
a feature request for path syntax for arrays because I can think of no
universally-applicable way to expect the engine team to do it.
--
Richard Gaskin
Fourth World Systems
Software Design and Development for the Desktop, Mobile, and the Web
____________________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list