swirl Guide to OmniMark 5   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
 
     
Arrays: multi-dimensional

Key-based indexing can be used to simulate multi-dimensional arrays.

One example of a two-dimensional array is a table. Each item in the table has a row and a column. Shelf item keys can contain the row number and the column number separated by a separator character like period (.). Alternatively, if each row and column has a "name", then those names can be used in the keys instead of the row and column numbers. The following code is an example of a two-dimensional array, with the shelf item keys composed of the row number and column number for each item, separated by a period:

  down-translate

  global integer row
  global integer col
  global stream table variable

  element table
     clear table
     set row to 0
     suppress

  element row
     increment row
     set col to 0
     suppress

  element col
     increment col
     set table { "%d(row).%d(col)"} to "%c"

An example of a three-dimensional array with which most readers will be familiar can be found with Rubik's Cube. Suppose we are using OmniMark to solve the cube. The cube is made up of 26 sub-cubes (the center, where you would expect to find the 27th, is empty and thus doesn't need to take up an item on our shelf). Each sub-cube is given a three-part key. The first part indicates where it is relative to the table: 1 if it's in the top layer, 2 if it's in the middle layer, and 3 if it's in the bottom layer. The second part of the key indicates if the sub-cube is in the left slice of the cube (1), the middle slice (2), or the right slice (3). Finally, the third part is used to tell if the sub-cube is facing us (1), in the middle (2), or facing away from us (3).

So, the top-left-front sub-cube would be indicated with a key of "1.1.1" and the bottom-right-rear sub-cube by "3.3.3". Note that there would be no item with a key of "2.2.2" because that is the empty position. An arbitrary position given by three integers, x, y, and z, can be specified by the key %d(x) . %d(y) . %d(z).

How this shelf would actually be used to solve Rubik's Cube is left as an exercise to the interested reader.

       
----

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ OMX ] [ OMX ] [ ERRORS ]

Generated: August 11, 2000 at 3:06:15 pm
If you have any comments about this section of the documentation, send email to docerrors@omnimark.com

Copyright © OmniMark Technologies Corporation, 1988-2000.