Nested Arrays

Rob Cozens rcozens at pon.net
Fri Nov 19 12:36:43 EST 2004


>>Is it possible to create nested arrays of the form A[X[i]] or 
>>deeper?  I tried but it doesn't seem to be working.
>
>This is unfortunately not supported (yet?)...

Greg, et al:

If you can live with notation like "A[X,i]" instead of "A[X[i]]", you 
can use discrete keyed variables:

on initializeArray @theArray,xBound,iBound,initialValue
    repeat with X = 1 to xBound
       repeat with i = 1 to yBound
           put initialValue into theArray[(X&comma&i)]
       end repeat
     end repeat
end initializeArray

function getElement @theArray,xBound,iBound
     return theArray[(xBound&comma&iBound)]
end getElement

on setElement @theArray,xBound,iBound,elementValue
     put elementValue into theArray[(xBound&comma&iBound)]
end setElement

Actually, if something like

    get "X[i]"
    put someValue into keyedVariable[it]

works,  you could even maintain "A[X,i]" syntax.

There is a set of generic array handlers in Serendipity_Library 
<http://wecode.org/serendipity/serendipity_downloader.htm> that 
support n-dimensional arrays, including array math and matrix math. 
However my array-processing handlers have proven to be slower than 
using keyed variable references as above.

-- 
Rob Cozens, Staff Conservator
Mendonoma Marine Life Conservancy
P.O. Box 217
Manchester, CA 95459-0217
(707) 895-2584

"Promoting a healthy and bountiful offshore environment."


More information about the use-livecode mailing list