Go to the previous, next section.

Array Operations

This package provides an implementation of extendable arrays with logarithmic access time.

Beware: the atom $ is used to indicate an unset element, and the functor $ /4 is used to indicate a subtree. In general, array elements whose principal function symbol is $ will not work.

To load the package, enter the query

| ?- use_module(library(arrays)).

@
Binds Array to a new empty array. Example:

| ?- new_array(A).

A = array($($,$,$,$),2) ? 

yes

@
Is true when Array actually is an array.

@
Element is the element at position Index in Array. It fails if Array[Index] is undefined.

@
Is like aref/3 except that Element is a new array if Array[Index] is undefined. Example:
| ?- arefa(3, array($($,$,$,$),2), E).

E = array($($,$,$,$),2) ? 

yes

@
Is as aref/3 except that Element is [] for undefined cells. Example:
| ?- arefl(3, array($($,$,$,$),2), E).

E = [] ? 

yes

@
List is a list with the pairs Index-Element of all the elements of Array. Example:

| ?- array_to_list(array($(a,b,c,d),2), List).

List = [0-a,1-b,2-c,3-d] ? 

yes
@
NewArray is the result of setting Array[Index] to Element. Example:
| ?- aset(3,array($($,$,$,$),2), a, Newarr).

Newarr = array($($,$,$,a),2) ? 

yes

Go to the previous, next section.