========================================================
(C)1993 Institute for New Generation Computer Technology
(Read COPYRIGHT for detailed information.)
========================================================

Vectors
=======
December 17, 1993
Takashi Chikayama (ICOT)

This document describes a temporary version of the vector data type of
KLIC.

Note: The implementation of vectors is a temporary solution to the
urgent requirements.  It is only a temporary solution: many features
that should be implemented are lacking, implemented features sometimes
do not behave as they should, and implementation efficiency is far
from ideal.

Nevertheless, thefeature might be useful for programs running on
sequential versions of KLIC.


1. Vectors

Vectors are fixed-length one-dimensional array of KL1 data.  The
length of a vector is determined on its creation.

Elements can be any KL1 data and, as other data structures of KL1, can
be left undefined when the data structure is created.

Elements are indexed by an integer beginning from 0.  For example, a
vector with 3 elements have elements numbered 0, 1 and 2.


2. Notation

Vectors can be denoted by a comma-separated list of elements in curly
braces, such as follows.

	{ 1, a, f(b), X }

A null vector (vectors with no elements at all) is denoted only by
curly braces, as follows.

	{}


3. Creating a New Vector

In addition to the notation described above, vectors can be
dynamically created during execution.  The following predicate can be
used to create a new vector.

 generic:new(vector, Vector, Length)
	A new vector with number of elements being Length is created
	and unified with String.  elements have 8 bits of width, which
	is the only element size available in the current version.
	The elements are initialized with integer 0.


4. Guard Predicates

The following predicates concerning strings can be used in the guard
parts of program clauses.

 generic:vector(Vector, Length)
	The number of elements of Vector is returned in Length.

 generic:element(Vector, Index, Element)
	An element with index Index of the vector Vector is unified
	with Element.  The index is zero origin.


5. Body Predicates

The following predicates concerning vectors can be used in the body
parts of program clauses.

 generic:element(Vector, Index, Element)
	An element with index Index of the vector Vector is unified
	with Element.  The index is zero origin.

 generic:set_element(Original, Index, NewElement, New)
	A new vector is unified with New.  The new vector has the same
	elements as the Original, except that the Index'th element is
	updated to NewElement.  The original vector is left untouched.
	The index is zero origin.

 generic:set_element(Original, Index, Element, NewElement, New)
	A new vector is unified with New.  The new vector has the same
	elements as the Original, except that the Index'th element is
	updated to NewElement.  The original vector is left untouched.
	The index is zero origin.  The original Index'th element is
	returned to Element.


5. Bugs

- The current implementation is quite naive.  Updating one element
  requires copying the whole vector, which is very slow.

- More sophisticated vector manipulation predicates, such as
  concatenation or slicing should be provided.

- Multidimensional arrays should also be provided.
