Like many other languages, Caché Basic provides multidimensional arrays, which you reference using subscripts. But arrays in Caché Basic are different, and more powerful, 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.
a(3, 7) = 4 + 2
println a(3, 7)
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 power Caché Basic arrays give you, you should learn to picture them like ordered trees. On the next few pages, you'll see a animated example of an array as an ordered tree, and this will also serve to introduce you to the other capabilities of arrays.
© 1997-2019 InterSystems Corporation, Cambridge, MA