YAP 7.1.0
Named Arrays

The YAP system includes experimental support for arrays. More...

Detailed Description

The YAP system includes experimental support for arrays.

Prolog support for old arrays code.

The support is enabled with the option YAP_ARRAYS

There are two very distinct forms of arrays in YAP The dynamic arrays are a different way to access compound terms created during the execution Like any other terms, any bindings to these terms and eventually the terms themselves will be destroyed during backtracking Our goal in supporting dynamic arrays is twofold First, they provide an alternative to the standard arg/3 built-in Second, because dynamic arrays may have name that are globally visible, a dynamic array can be visible from any point in the program In more detail, the clause

g(X) :- array_element(a,2,X).

will succeed as long as the programmer has used the built-in array/2 to create an array term with at least 3 elements in the current environment, and the array was associated with the name a The element X is a Prolog term, so one can bind it and any such bindings will be undone when backtracking Note that dynamic arrays do not have a type: each element may be any Prolog term

The static arrays are an extension of the database They provide a compact way for manipulating data-structures formed by characters, integers, or floats imperatively They can also be used to provide two-way communication between YAP and external programs through shared memory

In order to efficiently manage space elements in a static array must have a type Currently, elements of static arrays in YAP should have one of the following predefined types:

Arrays may be named or anonymous Most arrays will be named, that is associated with an atom that will be used to find the array Anonymous arrays do not have a name, and they are only of interest if the TERM_EXTENSIONS compilation flag is enabled In this case, the unification and parser are extended to replace occurrences of Prolog terms of the form X[I] by run-time calls to array_element/3 , so that one can use array references instead of extra calls to arg/3 As an example:

g(X,Y,Z,I,J) :-
X[I] is Y[J]+Z[I].

should give the same results as:

G(X,Y,Z,I,J) :-
array_element(X,I,E1),
array_element(Y,J,E2),
array_element(Z,I,E3),
E1 is E2+E3.

Note that the only limitation on array size are the stack size for dynamic arrays; and, the heap size for static (not memory mapped) arrays Memory mapped arrays are limited by available space in the file system and in the virtual memory space

The following predicates manipulate arrays:

[toc]


Class Documentation

◆ array/2

class array/2

array( +Name, +Size )

Creates a new dynamic array The array is allocated in the global stack (or heap) Elements can be any term.xs

The Size must evaluate to an integer The Name may be either an atom (named array) or an unbound variable (anonymous array)

Dynamic arrays are just a way to refer compound terms Hence, space for the array is recovered automatically on backtracking

◆ static_array_properties/3

class static_array_properties/3

static_array_properties(+Name,+Size,+Type)

static_array_properties(? Name, ? Size, ? Type)

Succeed if Name has a static array associated Moreover, the second arguent must unify with the Size and the third with the type

Show the properties size and type of a static array with name Name Can also be used to enumerate all current static arrays

This built-in will silently fail if the there is no static array with that name

Variables

int errno