[comp.sys.mac.hypercard] Multi-Dimensional Arrays

alan@mtxinu.UUCP (Alan Tobey) (04/29/88)

I hadn't seen any description of whether or not multidimensional
arrays are possible in HyperCard.   After trying a quick test, I've found
they're not only possible but easy to implement:

A one-dimensional array uses the familiar "item" construction usually
used in chunking expressions, where an item is any string of text
between commas.  The command

   put "foo" into item 5 of MyArrayVariable

creates a variable of the form ,,,,,foo,  -- hypercard will pad out
empty items in the array if necessary, so no initializing is needed.

This easily extends to at least three dimensions.  For a quick demo,
create a scrolling card field called "temp" and use this button script:

on mouseUp
 repeat with x = 1 to 10
  repeat with y = 1 to 5
   repeat with z = 1 to 3
    put  x & "." & y & "." & z into item z of item y of item x of array
    put item z of item y of item x of array & return after card field "temp"
   end repeat
  end repeat
 end repeat
end mouseUp

Haven't tried this in more than three dimensions, since I could never think
of a use for a four-dimensional array that I could comprehend!