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

Strings
=======
December 2, 1993
Takashi Chikayama (ICOT)

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

Note: The implementation of strings 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. Character String Constants

In the current version, character string constants should be denoted
as:

	string#"Characters of the string"

To include a doublequote symbol within the string, double it, as in
the following.

	string#"The character '""' (doublequote)"

These two doublequotes will actually be understood as one doublequote
character, and the contents of the string will be as follows.

	The character '"' (doublequote)


2. Creating a New String

In addition to the constant strings described above, strings can be
dynamically created during execution.  The following predicate can be
used to create a new string.

 generic:new(string, String, Length, 8)
	A new string with number of elements being Length is created
	and unified with String.  The last argument "8" means that
	elements have 8 bits of width, which is the only element size
	available in the current version.  The elements are
	initialized with integer 0 (null code).


3. Guard Predicates

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

 generic:string(String, Length, ElemSize)
	The number of elements of String is returned in Length and the
	element size (which is always 8) is returned in ElemSize.

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

 generic:string_less_than(String1, String2)
	Succeeds only when String1 is less than String2 in
	lexicographical order.

 generic:string_not_less_than(String1, String2)
	Succeeds only when String1 is _not_ less than String2 in
	lexicographical order.


4. Body Predicates

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

 generic:string(String, Length, ElemSize)
	The number of elements of String is returned in Length and the
	element size (which is always 8) is returned in ElemSize.

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

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

 generic:search_character(String, Start, End, Char, Where)
	The character Char is searched for in String, beginning from
	the position Start and ending before End.  If such a character
	is found, its index is unified with Where.  If not, Where is
	unified with -1.  The indices are zero origin.


5. Bugs

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

- More sophisticated search and manipulation predicates should be
  provided.
