Constant time vectors

Defining a vector is done initializing it to a given Zero element. The vector_set/3 update operation uses saved/2, therefore the old content of vectors is also subject to garbage collection.

vector_def(Name,Dim,Zero):- Max is Dim-1,
  saved(Zero,BBVal),
  for(I,0,Max), % generator for I from 0 to Max
    let(Name,I,BBVal), % def/3 or set/3 if needed
  fail.
vector_def(_,_,_).

vector_set(Name,I,Val):-saved(Val,BBVal),set(Name,I,BBVal).

vector_val(Name,I,Val):-val(Name,I,Val).

Building multi-dimensional arrays on these vectors is straightforward, by defining an index-to-address translation function.

The special case of a high-performance 2-dimension (possibly sparse) global array can be handled conveniently by using def/3, set/3, val/3 and saved/2 as in:

global_array_set(I,J,Val):-saved(Val,S),set(I,J,S).