Date: Fri, 9 Jun 1995 11:58:11 +0930 From: Matt Craig <mnmac@FLINDERS.EDU.AU> Subject: Re: multi-dimensional arraysLingo does multidimensional arrays just fine.
set myList to [] append myList,[1,2] append myList,[3,4] put getAt(getAt(myList,1),2)will return 2
Here is an example of how to make and get values for a multidimensional array.
PS This is a little unusual in that it actually makes a variably dimensional array, such that if you don't set a value for a position, that position isn't created, and getting a value for it will just return 0. This is nice for space saving, but a little odd to look at.
the syntax is
setMulti(list,list,anyvalue) getMulti(list,list)therefore if you only wanted to get a value for a variable list with one dimension called myList, at position 5, you would go
getMulti(myList,[5])but for position 5,4,7, all you need to do is
getMulti(myList,[5,4,7])
on setMulti array,posList,value
if listP(array) and listP(posList) then
if count(posList) > 1 then
set myPos to getAt(posList,1)
set truncList to posList + 0
deleteAt(truncList,1)
if myPos > count(array) then
set dummyList to []
setAt(array,myPos,dummyList)
end if
set nextList to getAt(array,myPos)
if not listP(nextList) then
set nextList to []
setAt(array,myPos,nextList)
end if
setMulti(nextList,truncList,value)
else
setAt(array,getAt(posList,1),value)
end if
end if
end
on getMulti array,posList
set value to 0
if listP(array) and listP(posList) then
if count(posList) > 1 then
set myPos to getAt(posList,1)
set truncList to posList + 0
deleteAt(truncList,1)
if myPos > count(array) then
return 0
exit
end if
set nextList to getAt(array,myPos)
if not listP(nextList) then
return 0
exit
end if
set value to getMulti(nextList,truncList)
else
set value to getAt(array,getAt(posList,1))
end if
end if
return value
end
Matt Craig