Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.

For information on migrating to InterSystems IRIS, see How to Migrate to InterSystems IRIS, available on the WRC Distributions page (login required).

Arrays

Like many other languages, ObjectScript provides multidimensional arrays, which you reference using subscripts. But arrays in ObjectScript are different, and more flexible, than regular arrays. First, just like regular, unsubscripted variables, you don't need to declare arrays, no matter the size or number of dimensions. Arrays are sparse; no space is reserved ahead of time, and no space is used until it's needed. As an example, consider an array used to keep track of the positions of pieces for a game of checkers. A checkerboard is 8x8. In other languages, an array Board(8,8) would use 64 memory locations, even though no more than 24 positions are ever occupied by checkers.

SAMPLES>set a(3, 7) = 4 + 2

SAMPLES>write a(3, 7)
6
SAMPLES>

generated description: tictactoe.gif

You can picture arrays in exactly the same way that you picture them in other languages, as lists or tables, as in the simple 3x3 array A shown here. But in order to understand the additional flexibility ObjectScript arrays give you, you should learn to picture them as ordered trees. On the next few pages, you'll see an animated example of an array as an ordered tree, and this will also serve to introduce you to the other capabilities of arrays.

Feedback