next up previous contents index
Next: Asserts/Retracts using Tries Up: Library Utilities Previous: Buffered, stream-oriented communication.   Contents   Index

Arrays

The module array1 in directory lib provides a very simple backtrackable array implementation. The predicates through which the array objects are manipulated are:

array_new(-Array, +Size)
array1
Creates a one dimensional empty array of size Size. All the elements of this array are variables.
array_elt(+Array, +Index, ?Element)
array1
True iff Element is the Index-th element of array Array.
array_update(+Array, +Index, +Elem, -NewArray)
array1
Updates the array Array such that the Index-th element of the new array is Elem and returns the new array in NewArray. The implementation is quite efficient in that it avoids the copying of the entire array.

A small example that shows the use of these predicates is the following:

           | ?- import [array_new/2, array_elt/3, array_update/4] from array1.

           yes
           | ?- array_new(A, 4), array_update(A,1,1,B), array_update(B,2,2,C),
                ( array_update(C,3,3,D), array_elt(D,3,E)
                ; array_update(C,3,6,D), array_elt(D,3,E)
                ; array_update(C,3,7,D), array_elt(D,3,E)
                ).

           A = array(1,2,3,_874600)
           B = array(1,2,3,_874600)
           C = array(1,2,3,_874600)
           D = array(1,2,3,_874600)
           E = 3;

           A = array(1,2,6,_874600)
           B = array(1,2,6,_874600)
           C = array(1,2,6,_874600)
           D = array(1,2,6,_874600)
           E = 6;

           A = array(1,2,7,_874600)
           B = array(1,2,7,_874600)
           C = array(1,2,7,_874600)
           D = array(1,2,7,_874600)
           E = 7;

           no



Luis Fernando P. de Castro 2003-06-27