Logiweb(TM)

7.10.1 Array creation and indexing

Prev Up Next Page 218 of 800 Search internet


A Logiweb array is a data structure built up from pairs and integers which represents a function from integers to values. For an array a and an integer i, a [[ i ]] denotes the value associated to the integer i by the array a.

Arrays are 'finite' in the sense that a [[ i ]] != true for at most finitely many integers i. We shall refer to the set of integers for which a [[ i ]] != true as the domain of the array a. Thus, the domain of any array is a finite set of integers.

In particular, there exists one array whose domain is the empty set. We shall refer to that array as the empty array. As usual, the heavily overloaded value true is used for representing nothingness, so it should come as no surprise that true represents the empty array. Thus, we have true [[ i ]] = true for all integers i.

The construct a [[ i -> v ]] returns an array which is identical to a except that the returned array maps i to v. As an example,

true [[ 1 -> 10 ]] [[ 2 -> 20 ]] [[ 3 -> 30 ]]

denotes an array which maps 1, 2, and 3 to 10, 20, and 30, respectively. As another example,

true [[ 1 -> 10 ]] [[ 2 -> 20 ]] [[ 3 -> 30 ]] [[ 1 -> true ]] [[ 3 -> 300 ]]

denotes an array which maps 2 and 3 to 20 and 300, respectively. The domain of the array comprises the integers 2 and 3. The integer 1 ends up being mapped to true so the integer 1 is kicked out of the domain by the fourth assignment above.

Logiweb is purely functional and assigning a value to an array has no side effects. Evaluation of a [[ i -> v ]] returns an array which maps i to v without affecting the value of a.

Note that one does not have to declare array bounds. Logiweb arrays expand and shrink as needed.

Logiweb arrays are implemented in such a way that they are efficient in most cases. In particular, they are efficient in these two cases:

Prev Up Next Page 218 of 800 Search logiweb.eu

Copyright © 2010 Klaus Grue, GRD-2010-01-05