YAP 7.1.0
Implementation Notes

This file works together with pl/arrays.yap and arrays.h.

This file works together with pl/arrays.yap and arrays.h.

YAP supports a very simple notion of arrays Arrays may be allocated dynamically or statically:

o anonymous arrays are created during execution and allocated in the heap They have the lifetime of any other other heap object Any term can be an argument to a dynamic array

Dynamic arrays are named as a free variable and are initialized with free variables

o named arrays are created during execution but allocated in the code space They have the lifetime of an heap object Any term can be an argument to a dynamic array

Named arrays are named with atoms and are initialized with free variables

Static arrays can be named through an atom They are initialized with []

Users create arrays by a declaration X array Arity If X is an atom A, then this it is a static array and A's the array name, otherwise X refers to a dynamic array

As in C, arrays start counting from 0

Users access arrays by a token X[I] or a[I], this token can appear anywhere within the computation, so a[2] = X[3*4] means that the second element of global array a should unify with the 12th element of array X The mechanism used to implement this is the same mechanism used to implement suspension variables

==== Representation:

Dynamic Arrays are represented as a compound term of arity N, where N is the size of the array Even so, I will not include array bound checking for now

|--------------------------------------------------------------|
| $ARRAY/N|....
|______________________________________________________________

Unbound Var is used as a place to point to

Static Arrays are represented as a special property for an atom, with field size and

A term of the form X[I] is represented as a Reference pointing to the compound term:

[]([I],X)