- 1.1.0
This module provides an efficient implementation of multidimensional arrays by terms of array terms.
The array indices are integers starting at 1 and the dimension of an array is a list of integers.
array_lists/2 makes conversions between an array and a list (of lists), which can be used to initialize an array to a list of values.
Array cells are accessed by unification with predicate cell/3.
This module includes module quantifiers.pl
for bounded quantification and is compatible with attributed variables,
clpfd and clpr libraries for creating arrays of constrained variables, and posting constraints on subscripted variables.
Array[Indices] notation defined here with multifile shorthand/3 predicate of library(quantifiers)
, can be used in quantifiers and let/2 expressions and library(clp)
constraints.
Array cells can also be modified by destructive assignment, backtrackable or not.
?- array(A, [3]), cell(A, [2], v).
A = array(_, v, _).
?- array(A, [2, 3]), cell(A, [2,2], 3).
A = array(array(_, _, _), array(_, 3, _)).
?- array(A, [2, 3]), cell(A, [2], X).
A = array(array(_, _, _), array(_A, _B, _C)),
X = array(_A, _B, _C).
?- array(A, [2, 3]), (set_cell(A, [1], 9) ; nb_set_cell(A, [2], 5); set_cell(A, [2,2],8)).
A = array(array(9, 9, 9), array(_, _, _)) ;
A = array(array(_, _, _), array(5, 5, 5)) ;
A = array(array(_, _, _), array(5, 8, 5)).
?- array_list(A, [2,3,4]), let([I=A[1],V=A[I]], writeln(a(I,V))).
a(2,3)
A = array(2, 3, 4).