\documentstyle{article}


\title{ An Introduction to ISETL}
\author{Gary Marc Levin \\ Clarkson University \\ Dept of Math and
Computer Science}

\begin{document}
\hyphenation{bool-ean}

\def\[{\begingroup \tt}
\def\]{\endgroup}
\def\div{\,{\tt div}\,}
\def\mod{\,{\tt mod}\,}

\arabic{enumi}
\alph{enumii}
\roman{enumiii}

\newcommand{\DS}{\begin{center}\begin{minipage}{10in}\tt\begin{tabbing}}
\newcommand{\DE}{\end{tabbing}\end{minipage}\end{center}}

\newcommand{\HEAD}[1]{\vspace{\medskipamount}\vspace{\stretch{3}}
                      \par\noindent
                      {\tt #1}}
\newcommand{\RULE}[1]{\vspace{\smallskipamount}\vspace{\stretch{1}}
                      \nopagebreak
                      \par
                      \nopagebreak
                       {\tt #1}\nopagebreak}
\newcommand{\COMMENT}[1]{\nopagebreak\begin{sloppypar}\nopagebreak
                          \begin{list}{}
                             {\setlength{\topsep}{-2pt}
                              \setlength{\parsep}{2pt}
                              \setlength{\leftmargin}{2\parindent}
			     }\nopagebreak
                         \item\nopagebreak #1
                           \end{list}
                           \end{sloppypar}
                          }
\maketitle

This introduction is intended for people who have had no
previous experience with SETL or ISETL,
but who are reasonably comfortable with learning
a new programming language.
Very few examples are given in the description,
but a large number of examples is distributed with the software.

This documentation appears as an appendix in a discrete math text
written by Nancy Baxter, Ed Dubinsky, and Gary Levin.
That text uses ISETL as a tool for teaching discrete mathematics.

\section{Running ISETL}

ISETL is an interpreted, interactive version of the programming language
SETL.
Written in C, it is invoked by typing a command line with
the executable name, say \[isetl\], along with optional file
names that are discussed below.\footnote{The Macintosh version
is clickable.  Therefore, statements about the command line do not
apply to the Mac.}

There is no compiler for ISETL.
When ISETL is running,
it prompts for input with the character ``\[>\]''.
Input consists of a sequence of expressions
(each terminated by a semicolon ``\[;\]''), statements, and programs.
Each input is acted upon as soon as it is entered.
The result of this action is explained below.
In the case of expressions,
the result includes its value being sent to standard output.
If you have not completed your entry,
you will receive the prompt ``\[>>\]'',
indicating that more is expected.

\begin{enumerate}

\item
ISETL is exited by typing ``\[!quit\]''.
It may also be exited by ending the standard input.
(In Unix, this is done by typing ctrl-D).

\item
A common mistake is omitting the semicolon after an expression.
ISETL will wait until it gets a semicolon before proceeding --- even if
a carriage return is entered.
The doubled prompt ``\[>>\]'' indicates that ISETL is expecting more
input.

\item
ISETL can get its input from sources other than the standard input.

\begin{enumerate}
    \item
    If there is a file with the name ``\[.isetlrc\]'' in the current directory,
    then the first thing ISETL will do is read this file.
    \footnote{On systems that use file extentions, this file will be called
    ``\[isetl.ini\]''.}

    \item
    Next, if the command line has any file names listed, ISETL will
    read each of these in turn.
    \footnote{This feature is system dependent.  Currently, neither the VMS 
     nor the Macintosh version has this feature.}

    Thus, if the command line reads,

    \DS isetl file.1 foo bar \DE


    ISETL will first read from the ``\[.isetlrc\]'' file, if it exists,
    and then from the file ``\[file.1\]'', then from ``\[foo\]'',
    and then from ``\[bar\]''.
    Finally, it is ready for input from the terminal.
    (This is only available under UNIX and MSDOS.)

    \item
    If there is a file available with the name, say ``\[file.2\]'' and
    ISETL is given (at any time), the input,

    \DS !include file.2 \DE

    (notice that there is {\em no} semicolon),
    then it will take its input from ``\[file.2\]''
    before being ready for any further input.
    The material in such a file is treated
    {\em exactly as if it were typed directly to the terminal,}
    and it can be followed by any additional information that
    the user would like to enter.

    Consider the following (rather contrived) example:
    Suppose that the file ``\[file.3\]'' contained the following data,

    \DS 5, 6, 7, 3, -4, "the" \DE

    Then if the user typed,

    \DS
    >   seta := \{\\
    >>  !include file.3\\
    !include file.3 completed\\
    >>  , x \};\\
    \DE

    the effect would be exactly the same as if the user had entered,

    \DS
    > seta := \{5, 6, 7, 3, -4, "the", x\};\\
    \DE

    The line ``\[!include file.3 completed\]''
    comes from ISETL and is always printed after an ``\[!include\]''.
\end{enumerate}

\item
Comments

If a dollar sign ``\[\$\]'' appears on a line,
then everything that appears until
the next carriage return is ignored by ISETL.

\item
After a program or statement has executed,
the values of global variables persist.
The user can then evaluate expressions in terms of these variables.
(See below for more detail on scope.)
\end{enumerate}


\section{Characters and Keywords}

\subsection{Character set.}  

The following is a list of characters used by ISETL.

\DS
] [ ; : = | \} \{ ) ( . \# ? * / + - \_ " > < \% \~\  ,   \\
\\
a {\rm -- } z \ \    A {\rm -- } Z  \ \   0 {\rm -- } 9
\DE

In addition, the following character-pairs are used.

\DS
:= \ \  .. \ \  ** \ \  /= \ \  <= \ \  >=
\DE


\subsection{Keywords.}

The following is a list of ISETL keywords.
\DS
\begin{tabular}{l l l l}
and&	from&	newat&	subset	\\
div&	fromb&	not&	take	\\
do&	frome&	notin&	then	\\
else&	func&	of&	to	\\
elseif&	if&	om (OM)&	true	\\
end&	impl&	or&	value	\\
exists&	in&	print&	while	\\
false&	less&	program&	where	\\
for&	local&	read&	with	\\
forall&	mod&	return	\\
\end{tabular}
\DE


\section{Identifiers.}

    \begin{enumerate}

    \item
    An identifier is a sequence of alphanumeric characters along with the
    underscore, ``\[\_\]''.
    It must begin with a letter.
    Upper or lower case may
    be used, and ISETL preserves the distinction.
    (I.e.: \[a\_\,good\_\,thing\] and \[A\_\,Good\_\,Thing\]
    are both legal and are different.)

    \item
    An identifier serves as a variable and can take on a value of any ISETL
    data type.
    The type of a variable is entirely determined by the value
    that is assigned to it and changes when a value of a different type is
    assigned to it.
    \end{enumerate}

\section{Simple Data Types.}

    \subsection{Integers.}
    \begin{enumerate}
    \item
    There is no limit to the size of integers.
    \footnote {No practical limit.  
    Actually limited to about 20,000 digits per integer.}
    \item
    An {\tt integer} constant is a sequence of one or more digits.
    It represents an unsigned integer.
    \item
    On output, long integers may be broken to accomodate 
    limited line length.  This format is not yet available for
    input.

    \end{enumerate}

    \subsection{Floating\_\,Point Numbers.}
    \begin{enumerate}
    \item
    The possible range of {\tt floating\_\,point} numbers is machine dependent.
    At a minimum, the values will have 5 place accuracy, with a range of
    approximately $10^{38}$.
    \item
    A {\tt floating\_\,point constant} is a sequence of one or more digits,
    followed by a period, ``\[.\]'',
    followed by one or more digits.
    Thus, \[2.0\] is legal, and \[2.\] and \[.5\] are illegal.
    
    It may be followed by an exponent.
    An exponent consists of one of the characters ``\[e\]'',
    ``\[E\]'', ``\[f\]'', ``\[F\]'' followed by a signed or unsigned
    {\tt integer}.
    The value of a {\tt floating\_\,point} constant
    is determined as is usual with scientific notation.
    As with integers, it is unsigned.
    Hence, for example, \[0.2\], \[2.0e-1\], \[20.0e-2\] are all equivalent.
    \item
    Different systems use different printed representations when
    floating point values are out of the machine's range.
    For example, when the value is too large, the Mac prints ``+++++''
    and the Sun prints "Infinity".
    \end{enumerate}

    \subsection{Booleans.}
    \begin{enumerate}
    \item
    A {\tt Boolean} constant is one of the keywords \[true\] or \[false\],
    with the obvious meaning for its value.
    \end{enumerate}

    \subsection{Strings.}
    \begin{enumerate}
    \item
    A {\tt string} constant is any sequence of
    characters preceded and followed by a double quote, ``\["\]''.
    The double quote may not be used in a {\tt string}.
    A {\tt string} may not be split across lines.
    Large {\tt string}s may be constructed using the
    operation of concatenation.

    {\em Warning:} Construction of {\tt string}s containing double quote is
    possible, but the output of such {\tt string}s may cause difficulties.
    \end{enumerate}

    \subsection{Atoms.}
    \begin{enumerate}
    \item
    Atoms are ``abstract points''.
    They have no identifying properties other than their individual existence.
    \end{enumerate}
    
    \subsection{Files.}
    \begin{enumerate}
    \item
    {\tt Files} are ISETL values
    that are created as a result of applying one of the pre-defined
    functions \[openr\], \[opena\], \[openw\].
    They correspond to external files in the operating system environment.
    \end{enumerate}

    \subsection{Undefined.}
    \begin{enumerate}
    \item
    The data type undefined
    has a single value, \[OM\].
    Any identifier that has not been given a value has the value \[OM\].
    It may also be entered as \[om\].
    \end{enumerate}



\section{Compound Data Types.}

\subsection{Sets.}
    \begin{enumerate}
    \item
    Only finite {\tt sets} may be represented in ISETL.
    The elements may be of any type, mixed heterogeneously.
    Elements occur at most once per {\tt set}.

    \item
    The order of elements is not significant
    in a {\tt set} and printing the value
    of a {\tt set} twice in succession could display the elements in
    different orders.

    \item
    \[OM\] may not be an element of a {\tt set}.
    Any set that would contain \[OM\] is considered to be undefined.

    \item
    An expression, or several expressions separated
    by commas, and, in either case, enclosed in \[\{ \}\] evaluates to
    the {\tt set} whose elements are the values of the
    enclosed expressions.

    \item
    The empty {\tt set} is denoted by \[\{ \}\].

    \item
    There are syntactic forms, explained in the grammar, for a finite {\tt set}
    that is an arithmetic progression of {\tt integer}s,
    and also for a finite {\tt set}
    obtained from a {\tt set} former in standard mathematical notation.

    For example, the value of the following expression

    \DS
    \{ x + y : x in \{-1,-3..-100\}, y in \{-1,-3..-100\} | x /= y\};
    \DE

    is the {\tt set} of all sums of two different odd negative {\tt integers}
    larger than $-100$.
    \end{enumerate}

\subsection{Tuples.}

    \begin{enumerate}
    \item
    A {\tt tuple} is an infinite sequence of components,
    of which only a finite number are defined.
    The components may be of any type, mixed heterogeneously. The values of
    components may be repeated.
    
    \item
    The order of the components of a {\tt tuple} is significant.
    By treating the {\tt tuple} as a function over the integers,
    you can extract individual components and slices of the {\tt tuple}.
    
    \item
    \[OM\] is a legal value for a component.

    \item
    An expression, or several expressions separated
    by commas, and, in either case, enclosed by \[[ ]\], evaluates to a
    {\tt tuple} whose defined components are the 
    values of the enclosed expressions.

    \item
    The empty {\tt tuple} is denoted by \[[ ]\].

    \item
    The syntactic forms for {\tt tuple}s of finite arithmetic progressions
    and {\tt tuple} formers are similar to those provided for {\tt sets}.
    The only difference is the use of square,
    rather than curly, brackets.

    \item
    The length of a {\tt tuple} is the largest index (counting from 1) for which
    a component is defined (that is, is not equal to \[OM\]).
    It can change at run-time.
    \end{enumerate}

\subsection{Maps.}

{\tt Map}s form a subclass of {\tt sets}.

    \begin{enumerate}

    \item
    A {\tt map} is a {\tt set} that is either empty or whose elements are all
    ordered pairs.
    An ordered pair is a {\tt tuple} whose first two components and no others are
    defined.

    \item
    There are two special operators for evaluating a {\tt map} at a point in its
    domain.
    Suppose that \[F\] is a {\tt map}.

	\begin{enumerate}

	\item
	\[F(EXPR)\] will evaluate to the value of the second component
	of the ordered pair whose first component
	is the value of \[EXPR\], provided there is exactly
	one such ordered pair in \[F\];
	otherwise, it evaluates to \[OM\].

	\item
	\[F\{EXPR\}\] will evaluate to the {\tt set} of all values
	of second components of ordered pairs in \[F\]
	whose first component is the value of \[EXPR\].
	If there are none such, its value is the empty {\tt set}.
	\end{enumerate}


    \item
    A {\tt map} in which no value appears more 
    than once as the first component of an
    ordered pair is called a {\em single-valued map} or {\em smap};
    otherwise, the {\tt map} is called a {\em multi-valued map} or {\em mmap}.
    \end{enumerate}


\section{Funcs.}

    \begin{enumerate}
    \item
    A {\tt func} is an ISETL value that may be applied to zero or more values
    passed to it as arguments.
    It then returns a value specified by the
    definition of the {\tt func}.
    Because it is a value, an ISETL {\tt func} can
    be assigned to an identifier, passed as an argument, etc.
    Evaluation of an ISETL {\tt func} can have side-effects determined by the
    statements in the definition of the {\tt func}.
    Thus, it also serves the purpose of what is often called a procedure.

    \item
    A {\tt func} is the computational 
    representation of a function, as a {\tt map}
    is the ordered pair representation, and a {\tt tuple} is the sequence
    representation.
    Just as {\tt tuple}s and {\tt map}s may be modified at a point 
    by assignment, so can {\tt func}s.
    However, if the value at a point is structured, you may not modify
    that at a point as well.

     \DS
     x := func(i); return char(i); end; \\
     x(97)~:=~"b"; \\
     x(97)(1)~:=~"abc";
     \DE

     \[x\] may be modified at a point.
     The assignment to \[x(97)\] is legal.
     However, the following assignment is not supported at this time,
     because you are trying to modify the structure of the value
     returned.

    \item
    A number of functions have been pre-defined as {\tt funcs} in ISETL.
    A list of their definitions is given later in this document.
    These are not keywords and may be changed by the user.
    They may not be modified at a point, however.

    \item
    It is possible for the user to define her/his own {\tt func}.
    This is done with the following syntax,

    \DS
    func\=    (list-of-parameters);\\
        \>    local list-of-local-ids;\\
        \>    value list-of-global-ids;\\
        \>    statements;\\
    end\\
    \DE

	\begin{enumerate}

	\item
	The declaration of local-ids may be omitted if no locals are needed.
	The declaration of global-ids represents global variables
	whose current values are to be remembered and used at the time
	of function invocation; these may be omitted if not needed.
	The list-of-parameters may be empty,
	but the pair of parentheses must be present.

	\item
	 Parameters and local-ids are local to the {\tt func}.
	 See below for a discussion of scope.

	\item
	The syntax described above is for an {\em expression} of type {\tt func}.
	As with any expression,
	it has an existence as a value, but no name.
	Thus, the definition will typically be part of an assignment
	statement, or passed as a parameter.
	As a very simple example, consider:

	\DS
	cube\_\,plus := \= func\= (x,y);\\
		     \>	    \> return x**3 + y;\\
		     \> end;\\
	\DE

	After having executed this input, ISETL will evaluate an
	expression such as \[cube\_\,plus(2,5);\] as {\tt 13}.

	\item
	Parameters are passed by value.
	If there are too many arguments, the extra arguments are ignored.
	If there are too few arguments, the extra parameters
	are assigned the value \[OM\].

	\item
	Scope is lexical (static) with retention.
	{\em Lexical } means that
	references to global variables are determined by
	where the {\tt func} was created,
	not by where it will be evaluated.
	{\em Retention } means that even
	if the scope that created the {\tt func} has been exited,
	its variables persist and can be used by the {\tt func}.

	By default, references to global variables will use the value
	of the variable at the time the function is invoked.
	The \[value\] declaration causes the value of the
	global variable {\em at the time the {\tt func} is created} to
	be used.

	\item
	Here is a more complicated example of the use of {\tt func}.
	As defined below, \[compose\] takes two functions as arguments
	and creates their functional composition.
	The functions can be any ISETL values that may be applied to a single
	argument; e.g. {\tt func, tuple, smap}.
	
	\DS
	compose := \= func \= (f,g); \\
	           \>      \> return \= func \= (x); \\
	           \>      \>        \>      \> return f(g(x)); \\
	           \>	   \>        \> end; \\
	           \> end; \\
	twice :=   \> func \> (a); \\
	           \>      \> return 2*a; \\
	           \> end; \\
	times4 :=  \> compose(twice,twice); \\
	\DE
	
	Then the value of \[times4(3)\] would be {\tt 12}.
	The value of \[times4\] needs to refer to the values of \[f\] and \[g\],
	and they remain accessible to \[times4\],
	even though \[compose\] has returned.

	\item
	Finally, here are some examples of functions modified at a point, and
	functions that capture the current value of a global.

	\DS
	f := \= func \= (x);\ \ \ \ \ \ \ \ \= \\
	     \>      \> return x + 4; \\
	     \> end ; \\
	gs := [ func(x); value N; return x+3*N; end :\\
\>\>\> N in [1..3] ]; \\
	f(3) := 21; \\
	\DE

	After this is executed, \[f(1)\] is {\tt 5}, \[f(2)\] is {\tt 6}, but 
\[f(3)\] is {\tt 21}.
	\[gs(2)(4)\] is {\tt  10} (\[4+3*2\]).
%	The function defined below by func and assigned to
%	the identifier \[curry\] takes as its single
%	parameter any value \[F\] for which \[F(x,y)\] makes sense
%	(e.g., a func, a map, etc.),
%	and returns a func \[G\] defined by: \[G(x)\] is a func whose
%	value at \[y\] is \[F(x,y)\].
%	Thus, after executing the following code, \[curry(F)\] will
%	be a func whose value at \[x\] is a func
%	that can be evaluated at \[y\],  and
%	\[curry(F)(x)(y)\] is \[F(x,y)\].
%
%\DS
%curry := \= func\= (F); \\
%	 \>	   \> return \= func\= (x); \\
%	 \>	   \>        \>     \> return \= func\= (y); \\
%	 \>	   \>	     \>     \>        \>     \> return F(x,y);\\
%	 \>	   \>	     \>     \>        \> end; \\
%	 \>	   \>        \> end; \\
%	 \> end; \\
%\DE
%
%	Hence, for example, if one then executed the following code,
%
%\DS
%plus := \= func\= (a,b); \\
%	\>     \>return a+b; \\
%	\> end; \\
% \\
%inc := curry(plus)(1); \\
%\DE
%	the resulting value of \[inc(3)\] would be \[4\].
	\end{enumerate}
\end{enumerate}


\section{The ISETL Grammar.}

\subsection{Terminology.}

\begin{enumerate}

\item
In what follows, the symbols \[ID\], \[INTEGER\], \[FLOATING\_\,POINT\],
\[BOOLEAN\], and \[STRING\] refer to the terms identifier and
{\tt integer}, {\tt floating point} number, {\tt Boolean}, and 
{\tt string} constants,
which have been specified above.
Any other symbol in capital letters is explained in the grammar.

%\item
%A symbol written in lower case is an ISETL keyword.
%It appears in the syntax exactly as written here.

\item
A statement enclosed in double quotes is an extra-grammatical explanation.

\item
Spaces are not allowed within any of the character pairs
listed in the section on Characters and Keywords,
nor within an \[ID\], \[INTEGER\] constant,
\[FLOATING\_\,POINT\] constant, or keyword.
Spaces are required between keywords, \[ID\]s, \[INTEGER\] constants,
and \[FLOATING\_\,POINT\] constants.

\item
ISETL treats carriage returns and tabs as spaces.
Any input can be spread across lines without changing the meaning,
and ISETL will not
consider it to be complete until a semicolon ``\[;\]'' is entered.
The only exceptions to this are the \[!include\] input,
which is ended with a carriage return,
and the fact that a quoted {\tt string} cannot be typed on more than one line.
\end{enumerate}

\subsection{The Grammar.}

The annotated grammar below is presented in three columns.
The first column is the symbol being defined,
the second column contains a list of the possibilities for that symbol,
and the third column, when present, provides additional explanation.

\HEAD{INPUT}
\COMMENT{Can be typed at the terminal or read from a file.}

\RULE{PROGRAM}
\RULE{STMT}
\RULE{EXPR ;}
\COMMENT{The \[EXPR\] is evaluated
and the result is sent to standard output.}

\HEAD{PROGRAM}
\COMMENT{Usually read from a file.}
\RULE{program ID ; STMTS ; end ;}
\COMMENT{Of course, it can appear on several lines with the
usual indented format.}

\HEAD{STMTS}
\RULE{\rm ``One or more instances of \[STMT\]''}

\HEAD{STMT}
\RULE{LHS := EXPR ;}
\COMMENT{
The left hand side is evaluated to determine
the target(s) for the assignment,
and the right hand side is evaluated.
Then the assignment is made.
If there are some targets for which there
are no values to be assigned, then they receive the
value, \[OM\].  If there are values to be assigned but
no corresponding targets, then the values are ignored.

Examples:

    \DS a := 4;  \DE

\[a\] is changed to contain the value \[4\].

    \DS [a,b] := [1,2]; \DE

\[a\] is assigned \[1\] and \[b\] is assigned \[2\].

    \DS [x,y] := [y,x]; \DE

Swap \[x\] and \[y\].

    \DS f(3) := 7; \DE

If \[f\] is a {\tt tuple}, then the effect of this statement
is to assign \[7\] as the value of the third component of \[f\].
If \[f\] is a {\tt map}, then its effect is to replace all pairs beginning
with \[3\] by the pair \[[ 3 , 7 ]\] in the set of ordered pairs \[f\].
If \[f\] is a {\tt func}, then \[f(3)\] will be \[7\], and all other values
of \[f\] will be as they were before the assignment.}

\RULE{EXPR ;}
\COMMENT{The expression is evaluated and the value ignored.}

\RULE{for   ITERATOR do STMTS end ;}
\COMMENT{The \[STMTS\] are executed for each instance generated by the
iterator.
Optionally, one may close with \[end for\].}

\RULE{while EXPR do STMTS end ;}
\COMMENT{\[EXPR\] must evaluate to a {\tt BOOLEAN} value.  \[EXPR\] is evaluated
and the \[STMTS\] are executed repetitively as long as this
value is equal to {\tt true}.
Optionally, one may close with \[end while\].}

\RULE{take LHS frome LHS ;}
\COMMENT{The second \[LHS\] must evaluate to a {\tt tuple} (or a {\tt string}).
The value of its
last defined component (or last character)
is assigned to the first \[LHS\] and
replaced by \[OM\] in the {\tt tuple} (deleted from the {\tt string}).}

\RULE{take LHS fromb LHS ;}
\COMMENT{The second \[LHS\] must evaluate to a {\tt tuple} (or a {\tt string}).
The value of its
first component (defined or not) (first character) is assigned to the first
\[LHS\] and all components of the {\tt tuple} (characters of the {\tt string})
are shifted left one place.
That is, the new value of the $i^{th}$ component is the
old value of the $(i+1)^{st}$ component ($i = 1,2,...$).}

\RULE{take LHS from LHS ;}
\COMMENT{The second \[LHS\] must evaluate to a {\tt  set}.  An arbitrary
element of the {\tt set} is assigned to the
first \[LHS\] and removed from the {\tt set}.}

\RULE{read LHS\_\,LIST ;}
\COMMENT{ISETL gives a question mark ``\[?\]'' prompt and waits until an
expression has been entered.  This \[EXPR\] is evaluated and
the result is assigned to the first item in \[LHS\_\,LIST\].  This
is repeated for each item in \[LHS\_\,LIST\].
{\em Note}: If a \[read\] statement appears in an \[!include\] file,
then ISETL will look at the next input in that
file for the expression(s) to be read.}

\RULE{read LHS\_\,LIST from EXPR ;}
\COMMENT{This is the same as \[read LHS\_\,LIST;\] except that \[EXPR\]
must have a value of type {\tt file}.  The values to be read
are then taken from the external file specified by the
value of \[EXPR\].
If there are more values in the file than items in \[LHS\_\,LIST\],
then the extra values are left to be read later.  If there
are more items in \[LHS\_\,LIST\] than values in the file, then
the extra items are assigned the value \[OM\].  In the latter
case, the function \[eof\] will return {\tt true}, when given the file as
parameter.
Before this statement is executed, the external file in
question must have been opened for reading by the
pre-defined function \[openr\] (see the section on file functions).}

\RULE{print EXPR\_\,LIST ;}
\COMMENT{Each expression in \[EXPR\_\,LIST\] is evaluated and printed on
standard output. The output values are formated to show
their structure, with line breaks at reasonable positions
and meaningful indentation.  The only problem is with very
long {\tt string}s.  If a {\tt string} is too long to fit on the screen,
the front of the {\tt string} is printed, followed by ellipses
and a length indicator.}

\RULE{print EXPR\_\,LIST to EXPR ;}
\COMMENT{Again \[EXPR\] must be a value of type {\tt file}.
The values are written to the external file specified
by the value of \[EXPR\].
Before executing this statement, the external file
in question must have been opened for printing by
one of the pre-defined functions \[openw\] or \[opena\]
(see the section on file functions).}

\RULE{return ;}
\COMMENT{
\[return\] is only meaningful inside a \[func\].
Its effect is to terminate execution of
a {\tt func} and return the value \[OM\] to the caller.
ISETL inserts \[return;\] just before the \[end\] of every \[func\].
If \[return\] appears at the ``top level'', i.e. as input to the
terminal, a run time error will occur.
}

\RULE{return EXPR ;}
\COMMENT{Same as \[return;\] except that \[EXPR\] is evaluated and its
value is returned as the value of the \[func\].}

\HEAD{IF\_\,STMT}

\RULE{if EXPR then STMTS ELSE\_\,IFS ELSE\_\,PART end}
\COMMENT{
The \[EXPR\]s after \[if\] and \[elseif\] are evaluated in order until one
is found to be {\tt true}.
The \[STMTS\] following the associated \[then\] are executed.
If no \[EXPR\] is found to be {\tt true},
the \[STMTS\] in the \[ELSE\_\,PART\] are executed.
In this last case, if the \[ELSE\_\,PART\] is omitted, this statement
has no effect.
Optionally, one may close with \[end if\].}

\HEAD{ELSE\_\,IFS}

\RULE{\rm ``zero or more repetitions of the following''}

\RULE{elseif EXPR then STMTS}

\HEAD{ELSE\_\,PART}

\RULE{\rm ``may be omitted''}

\RULE{else STMTS}

\HEAD{ITERATOR}

\RULE{ITER\_\,LIST}

\RULE{ITER\_\,LIST | EXPR}
\COMMENT{\[EXPR\] must evaluate to a {\tt  BOOLEAN}.  Generates only those
instances generated by \[ITER\_\,LIST\] for which the
value of \[EXPR\] is {\tt true}.}

\HEAD{ITER\_\,LIST}

\RULE{\rm ``one or more \[SIMPLE\_\,ITERATOR\]s separated by commas.''}
\COMMENT{Generates all possible instances for every combination
of the \[SIMPLE\_\,ITERATOR\]s.  The first \[SIMPLE\_\,ITERATOR\]
advances most slowly.  Subsequent iterators may
depend on previously bound values.}

\HEAD{SIMPLE\_\,ITERATOR}
\COMMENT{A \[SIMPLE\_\,ITERATOR\] generates a number of instances for
which an assignment is made.  These assignments are
local to the iterator and when it is exited, all
previous values of \[ID\]s that were used as local
variables are restored.  That is, these \[ID\]s are
``bound variables'' whose scope is the construction containing the
iterator.
(e.g., \[for\]-loops, quantifiers, formers, etc. ) }

\RULE{BOUND\_\,LIST in EXPR}
\COMMENT{\[EXPR\] must evaluate to a {\tt set}, {\tt tuple}, or {\tt string}.
The instances generated are all possibilities in which
each \[BOUND\] in \[BOUND\_\,LIST\] is assigned a value
that occurs in \[EXPR\].}

\RULE{BOUND = ID ( BOUND\_\,LIST )}
\COMMENT{Here \[ID\] must have the value of an 
{\tt smap}, {\tt tuple}, or {\tt string},
and \[BOUND\_\,LIST\] must have the correct number of occurrences of
\[BOUND\] corresponding to the parameters of \[ID\].
The resulting instances are
those for which all occurrences of \[BOUND\] in \[BOUND\_\,LIST\] have all
possible legal values and \[BOUND\] is assigned the corresponding
value.}

\RULE{BOUND = ID \{ BOUND\_\,LIST \} }
\COMMENT{Same as the previous one for the case in which \[ID\] is an
{\tt mmap}.}

\HEAD{BOUND\_\,LIST}

\RULE{\rm ``one or more \[BOUND\], separated by commas'' }

\HEAD{BOUND}
\RULE{\~\  }
\COMMENT{Corresponding value is thrown away.}

\RULE{ID }
\COMMENT{Corresponding value is assigned to \[ID\].}

\RULE{[ BOUND\_\,LIST ] }
\COMMENT{Corresponding value must be a {\tt tuple}, and elements of
the {\tt tuple} are assigned to corresponding elements in
the \[BOUND\_\,LIST\].}

\HEAD{SELECTOR}
\COMMENT{A {\tt tuple}, {\tt string}, {\tt map}, or {\tt func} (pre- or user-
defined) may be followed by a \[SELECTOR\], which has the
effect of specifying a value or group of values in the
range of the {\tt tuple}, {\tt string}, {\tt map}, or {\tt func}.  Not all
of the following \[SELECTOR\]s can be used in all four cases.
}

\RULE{\{ EXPR\_\,LIST \} }
\COMMENT{Must be used with an {\tt mmap}.  If the \[EXPR\_\,LIST\] has more than
one element it is equivalent to what it would be if the
list were enclosed in square brackets, \[[ ]\].  Thus a
function of several variables is interpreted as a
function of one variable --- the vector ({\tt tuple}) whose
components are the individual variables.}

\RULE{( EXPR\_\,LIST ) }
\COMMENT{Must be used with an {\tt smap}, {\tt tuple}, {\tt string}, or
{\tt func}.  If it is used with a {\tt tuple} or {\tt string}, then
\[EXPR\_\,LIST\] can only have one element, which must evaluate
to a positive {\tt integer}.  Same remark as previous for the
case in which the list has more than one element.}

\RULE{( EXPR ..\ EXPR ) }
\COMMENT{Must be used with a {\tt tuple} or {\tt string}, and both instances
of \[EXPR\] must evaluate to a positive {\tt integer}.

The value is the slice of the original {\tt tuple} or {\tt string} in
the range specified by the two occurrences of \[EXPR\].
There are some special rules in this case.
To describe them, suppose that the first \[EXPR\] has the
value \[a\] and the second has the value \[b\] so that the
selector is \[(a..b)\].

    \begin{center}
    \begin{tabular}{l l}
    $a \leq b$&	value is the {\tt tuple} or {\tt string} with components\\
	    &defined only at the {\tt integer}s from $1$ to $b-a+1$,\\
	    &inclusive.  The value of the $i^{th}$ component is\\
	    &the value of the $(a+i-1)^{st}$ component of the\\
	    &value of \[EXPR\].\\
    $a = b+1$&	value is the null {\tt tuple}.\\
    $a > b+1$& run-time error.\\
    \end{tabular}
    \end{center}
}

\RULE{( ..\ EXPR ) }
\COMMENT{Means the same as \[(1 ..\ EXPR)\].}

\RULE{( EXPR ..\ ) }
\COMMENT{Means the same as \[( EXPR ..\ EXPR )\] where the second \[EXPR\]
is equal to the length of the {\tt tuple} or {\tt string}.}

\RULE{( ) }
\COMMENT{Used with a {\tt func} that has no parameters.  It also
works with an {\tt smap} with \[[ ]\] in its domain.}

\HEAD{FORMER}
\COMMENT{Generates the values to be used in expressions that
evaluate to a {\tt set} or a {\tt tuple}.}

\RULE{EXPR : ITERATOR }
\COMMENT{The value of \[EXPR\] for each instance generated by the
\[ITERATOR\].}

\RULE{EXPR\_\,LIST }
\COMMENT{Values are explicitly listed.}

\RULE{EXPR ..\ EXPR }
\COMMENT{Both occurrences of \[EXPR\] must evaluate to {\tt integer}.
Generates all {\tt integer}s beginning with the first \[EXPR\]
and increasing by {\tt 1} for as long as the second \[EXPR\]
is not exceeded.  If the first \[EXPR\] is larger than the
second, no values are generated.}

\RULE{EXPR , EXPR ..\ EXPR }
\COMMENT{All three occurrences of \[EXPR\] must evaluate to {\tt integer}.
Generates all {\tt integer}s beginning with the first \[EXPR\]
and incrementing by the value of the second \[EXPR\] minus
the first \[EXPR\].  If this difference is positive, it
generates those {\tt integer}s that are not greater than
the third \[EXPR\].  If the difference is negative, it
generates those {\tt integer}s that are not less than the
third \[EXPR\].  If the difference is zero, no {\tt integers}
are generated.}

\HEAD{LHS}
\COMMENT{The target for anything that has the effect of an
assignment.}

\RULE{ID }

\RULE{LHS SELECTOR }
\COMMENT{\[LHS\] must evaluate to a {\tt tuple}, {\tt string}, or {\tt map}.
\[LHS\] is modified by replacing the components designated by selector.}

\RULE{[ LHS\_\,LIST ]}

\HEAD{LHS\_\,LIST}

\RULE{\rm ``One or more instances of \[LHS\], separated by commas''}
\COMMENT{Thus the input,

    \DS [A, B, C] := [1, 2, 3]; \DE

has the effect of replacing \[A\] by \[1\], \[B\] by \[2\],
and \[C\] by \[3\].}

\RULE{\rm ``Any \[LHS\] in the list can be replaced by \[\~\ \]''}
\COMMENT{The effect is to omit any assignment to a \[LHS\] that has
been so replaced.  Thus the input,

    \DS [A, \~\ , C] := [1, 2, 3]; \DE

replaces \[A\] by \[1\], \[C\] by \[3\].}

\HEAD{EXPR}
\COMMENT{The first few in the following list are values of
simple data types and they have been discussed
before.}

\RULE{ID}

\RULE{INTEGER}

\RULE{FLOATING\_\,POINT}

\RULE{STRING}

\RULE{true}

\RULE{false}

\RULE{OM}

\RULE{newat}
\COMMENT{The value is a new {\tt atom}, different from any other
{\tt atom} that has appeared at the time it is invoked.}

\RULE{FUNC\_\,CONST}
\COMMENT{A user-defined {\tt func}.}

\RULE{( EXPR )}
\COMMENT{Any expression can be enclosed in parentheses.  The
value is the value of \[EXPR\] enclosed in parentheses.}

\RULE{[ FORMER ]}
\COMMENT{Evaluates to the {\tt tuple} of those values generated by
\[FORMER\] in the order that former generates them.}

\RULE{\{ FORMER \}}
\COMMENT{Evaluates to the {\tt set} of those values generated by
\[FORMER\].}

\RULE{\# EXPR}
\COMMENT{\[EXPR\] must be a {\tt set}, {\tt tuple}, or {\tt string}. 
The value is
the cardinality of the {\tt set}, the length of the {\tt tuple},
or the length of the {\tt string} as the case may be.}

\RULE{EXPR SELECTOR}
\COMMENT{\[EXPR\] must evaluate to an ISETL value that is, in the
general sense, a function.  That is, it must be a {\tt map},
{\tt tuple}, {\tt string}, or {\tt func}.
See \[SELECTOR\].}   

\RULE{EXPR . ID EXPR}
\COMMENT{This is equivalent to \[ID(EXPR,EXPR)\].  (Space
after the ``\[.\]'' is optional.)}

\RULE{EXPR ? EXPR}
\COMMENT{The value of the first \[EXPR\], if it is not \[OM\]; otherwise
the value of the second \[EXPR\].}

\COMMENT{
In general, arithmetic and comparisons may mix {\tt integers} and 
{\tt floating\_\,point}.
The result is an {\tt integer} if both operands are {\tt integer}s and
{\tt floating\_\,point}, otherwise.
For simplicity, we will use the term {\tt number} to mean a value that
is either {\tt integer} or {\tt floating\_\,point}.
}

\RULE{EXPR ** EXPR}
\COMMENT{The values of the two expressions must be {\tt number}s.
The operation is exponentiation.
}

\RULE{EXPR * EXPR}
\COMMENT{If both instances of \[EXPR\] evaluate to {\tt number}s,
this is multiplication.
If both evaluate to {\tt sets}, this is intersection.
If one instance of \[EXPR\] evaluates to {\tt integer},
and the other to a {\tt tuple} or {\tt string}, then the value is
the {\tt tuple} or {\tt string}, concatenated with itself the
{\tt integer} number of times, if the {\tt integer} is positive;
and the empty {\tt tuple} or {\tt string}, if the {\tt integer} is less than or
equal to zero.}

\RULE{EXPR / EXPR}
\COMMENT{Both instances of \[EXPR\] must evaluate to {\tt number}s.
The value is the result of division,
and is of type {\tt floating\_\,point}.}

\RULE{EXPR mod EXPR}
\COMMENT{Both instances of \[EXPR\] must evaluate to {\tt integer} and the
second must be positive.  The result is the remainder,
and the following condition is always satisfied,

    $$0 \leq a \mod b < b$$.}

\RULE{EXPR div EXPR}
\COMMENT{Both instances of \[EXPR\] must evaluate to {\tt integer}, and the
second must be non-zero.  The value is integer division
defined by the following two relations,

    \DS
    $(a \div b) * b + (a \mod b) = 0$\ \ \     \=	{\rm for} $b>0$\\
    $a \div (-b) = -(a \div b)$	               \>	{\rm for} $b<0$.\\
    \DE
}

\RULE{EXPR + EXPR}
\COMMENT{If both instances of \[EXPR\] evaluate to 
{\tt number}s, this is addition.
If both instances of \[EXPR\] evaluate to {\tt sets}, then this
is union.
If both instances of \[EXPR\] evaluate to {\tt tuple}s or {\tt string}s,
then this is concatenation.}

\RULE{EXPR - EXPR}
\COMMENT{If both instances of \[EXPR\] evaluate to
{\tt number}s, this is subtraction.
If both instances of \[EXPR\] evaluate to {\tt set}s, then this
is {\tt set} difference.}

\RULE{EXPR with EXPR}
\COMMENT{The value of the first \[EXPR\] must be a {\tt set} or {\tt tuple}.  If
it is a {\tt set}, the value is that {\tt set} with the value of the
second \[EXPR\] added as an element.  If it is a {\tt tuple},
the value of the second \[EXPR\] is assigned to the value
of the first component after the last defined component
of the {\tt tuple}.}

\RULE{EXPR less EXPR}
\COMMENT{The value of the first \[EXPR\] must be a {\tt set}.  The value is
that {\tt set} with the value of the second \[EXPR\] removed, if it
was present.}

\RULE{EXPR = EXPR}
\COMMENT{The test for equality of any two ISETL values.}

\RULE{EXPR /= EXPR}
\COMMENT{Negation of \[EXPR=EXPR\].}

\RULE{EXPR <  EXPR}
\RULE{EXPR >  EXPR}
\RULE{EXPR <= EXPR}
\RULE{EXPR >= EXPR}
\COMMENT{
For all the above inequalities,
both instances of \[EXPR\] must evaluate to the same
type, which must be {\tt number} or {\tt string}.
For {\tt number}s, this is the test for the
standard arithmetic ordering, and for {\tt string}s, it
is the test for lexicographic ordering.}

\RULE{EXPR in EXPR}
\COMMENT{The second \[EXPR\] must be a {\tt set}, 
{\tt tuple}, or {\tt string}.  For
{\tt set}s and {\tt tuple}s, this is the test for membership.
For {\tt string}s, it is the test for substring.}

\RULE{EXPR notin EXPR}
\COMMENT{Negation of \[EXPR in EXPR\].}

\RULE{EXPR subset EXPR}
\COMMENT{Both instances of \[EXPR\] must be {\tt set}s.  This is the
test for the value of the first \[EXPR\] to be
a subset of the value of the second \[EXPR\].}

\RULE{EXPR and EXPR}
\COMMENT{Both instances of \[EXPR\] must evaluate to {\tt BOOLEAN}.
Logical conjunction.
If the left operand is {\tt false}, the right operand is not evaluated.}

\RULE{EXPR or EXPR}
\COMMENT{Both instances of \[EXPR\] must evaluate to {\tt  BOOLEAN}.
Logical disjunction.
If the left operand is {\tt true}, the right operand is not evaluated.}

\RULE{EXPR impl EXPR}
\COMMENT{Both instances of \[EXPR\] must evaluate to {\tt  BOOLEAN}.
Logical implication.}

\RULE{not EXPR}
\COMMENT{\[EXPR\] must evaluate to {\tt BOOLEAN}.
Logical negation.}

\RULE{+ EXPR}
\COMMENT{\[EXPR\] must evaluate to a {\tt number}.
Identity function.}

\RULE{- EXPR}
\COMMENT{\[EXPR\] must evaluate to a {\tt number}.
Negative of \[EXPR\].}

\RULE{\% BINOP EXPR}
\COMMENT{\[EXPR\] must evaluate to a {\tt set}, {\tt tuple}, or {\tt string}.
Say that the elements in
\[EXPR\] are \[x1\], \[x2\],...,\[xN\] (\[N=\#EXPR\]).
If \[N=0\], then the value is \[OM\].
If \[N=1\], then the value is the single element.
Otherwise, \[\%BINOP EXPR\] equals
\DS
x1 BINOP x2 BINOP $\ldots$ BINOP xN 
\DE
associating to the left.

If \[EXPR\] is a {\tt set}, then the selection of elements is
made in arbitrary order, otherwise it is made in
the order of the components of \[EXPR\].}

\RULE{EXPR \% BINOP EXPR}
\COMMENT{The second instance of \[EXPR\] must evaluate to a {\tt set},
{\tt tuple}, or {\tt string}.
If the first \[EXPR\] is \[a\], and the values in the second are
\[x1\], \[x2\],...,\[xN\] as above, then the value is:
\DS
a BINOP x1 BINOP x2 BINOP $\ldots$ BINOP xN 
\DE
associating to the left.
}

\RULE{exists ITER\_\,LIST | EXPR}
\COMMENT{\[EXPR\] must evaluate to a {\tt BOOLEAN}.
If \[ITER\_\,LIST\] generates at least
one instance in which \[EXPR\] evaluates to {\tt true}, then the
value is {\tt true}; otherwise it is {\tt false}.}

\RULE{forall ITER\_\,LIST | EXPR}
\COMMENT{\[EXPR\] must evaluate to a {\tt BOOLEAN}.  If every instance
generated by \[ITER\_\,LIST\] is such that \[EXPR\] evaluates to
{\tt true}, then the value is {\tt true}; otherwise it is {\tt false}.}

\RULE{EXPR where DEFNS end}
\COMMENT{The value is the value of the \[EXPR\] preceeding \[where\],
evaluated in the current environment with the \[ID\]s in
the \[DEFNS\] added to the environment and initialized to
the corresponding \[EXPR\]s.  The scope of the \[ID\]s is
limited to the \[where\] expression.
The \[DEFNS\] can modify \[ID\]s defined in earlier \[DEFNS\] in the
same \[where\] expression.
}

\HEAD{DEFNS}

\RULE{\rm ``Zero or more instances of \[DEFN\]''}

\HEAD{DEFN}

\RULE{BOUND := EXPR ;}

\RULE{ID SELECTOR := EXPR ;}

\HEAD{EXPR\_\,LIST}

\RULE{\rm ``One or more instances of \[EXPR\] separated by commas''}

\HEAD{BINOP}

\RULE{\rm ``Any binary operator (\[+\], \[-\], \[*\], \[**\],
\[/\], \[div\], \[mod\], \[with\], \[less\], \[and\], \[or\],
\[impl\]) or an \[ID\]
whose value is a function of two parameters.''}

\HEAD{FUNC\_\,CONST}

\RULE{FUNC\_\,HEAD LOCALS VALUES STMTS end}
\COMMENT{This is the syntax for user-defined {\tt funcs}.
Optionally, one may close with \[end func\].}

\HEAD{FUNC\_\,HEAD}

\RULE{func ( ID\_\,LIST ) ;}
\COMMENT{In this case, there are parameters.}

\RULE{func ( ) ;}
\COMMENT{In this case, there are no parameters.}

\HEAD{LOCALS}

\RULE{local ID\_\,LIST ;}
\COMMENT{The appearance of this in \[FUNC\_\,CONST\] is optional.}

\HEAD{VALUES}

\RULE{value ID\_\,LIST ;}
\COMMENT{The appearance of this in \[FUNC\_\,CONST\] is optional.
\[VALUES\] and \[LOCALS\] may be repeated and appear in any order.
}

\HEAD{ID\_\,LIST}

\RULE{\rm ``One or more instances of \[ID\] separated by commas.''}

%\vspace{\stretch{1000}}

\section{Pre-defined Functions}

\subsection{Functions on integers.}

In each of the following, \[EXPR\] must evaluate to {\tt integer}.

\begin{enumerate}
\item
\[even(EXPR)\].  The test for even.

\item
\[odd(EXPR)\].  The test for odd.

\item
\[float(EXPR)\].
\sloppypar The value is the value of \[EXPR\] converted 
to {\tt floating\_\,point}.

\item
\[char(EXPR)\].  The value is the one-character {\tt string}
whose (machine dependent) index is
the value of \[EXPR\].
\end{enumerate}


\subsection{Functions on floating point numbers.}

In each of the following, \[EXPR\] must evaluate to {\tt floating\_\,point}.

\begin{enumerate}
\item
\[ceil(EXPR)\].
The value is the smallest {\tt integer} not smaller than the value of \[EXPR\].

\item
\[floor(EXPR)\].  The value is the largest {\tt integer} not larger than
the value of \[EXPR\].

\item
\[fix(EXPR)\].
The value is the same as  \[floor(EXPR)\] if \[EXPR>=0\],
and the same as \[ceil(EXPR)\] if the value of \[EXPR<=0\].
In other words, the fractional part is discarded.
\end{enumerate}


\subsection{Functions on Sets.}

In each of following, {\tt EXPR} must evaluate to a {\tt set}.

\begin{enumerate}

\item
\[arb(EXPR)\].  An element of \[EXPR\], selected arbitrarily.
If the value of \[EXPR\] is \[\{ \}\],
then the value of the function is \[OM\].

\item
\[pow(EXPR)\]. The value is the {\tt set} of all subsets 
of the value of \[EXPR\].

\item
\[npow(EXPR,EXPR)\].
One \[EXPR\] must be a {\tt set}, and the other a non-negative {\tt integer}.
The value is the {\tt set} of all subsets of the {\tt set} whose
cardinality is equal to the {\tt integer}.
This {\tt func} is defined in \[.isetlrc\].
This will eventually change.
If you do not have the standard \[.isetlrc\],
you do not have this {\tt func}.
\end{enumerate}



\subsection{Functions on maps.}

In each of the following, \[EXPR\] must evaluate to a {\tt map}.

\begin{enumerate}

\item
\[domain(EXPR)\].  The value is the 
{\tt set} of all values that appear as the first
component of an element of the value of \[EXPR\].

\item
\[image(EXPR)\].  The value is the 
{\tt set} of all values that appear as the second
component of an element of the value of \[EXPR\].
\end{enumerate}

\subsection{Standard mathematical functions.}

\begin{enumerate}
\item
Each of the following takes a  single {\tt floating\_\,point} argument.
The value is a {\tt floating\_\,point} approximation
to the value of the corresponding mathematical function.

{\tt exp}, {\tt ln}, {\tt log}, {\tt sqrt}, {\tt sin}, {\tt cos}, {\tt tan}, 
{\tt asin}, {\tt acos}, {\tt atan}, {\tt sinh}, {\tt cosh}, {\tt tanh},
{\tt asinh}, {\tt acosh}, {\tt atanh}.


\item
\sloppypar In each of the following, \[EXPR\] must evaluate to 
{\tt integer} or {\tt floating\_\,point}.
The value is the value of the mathematical function in the
same type as the value of \[EXPR\].

\begin{enumerate}
\item
\[sgn(EXPR)\]. If \[EXPR\] is positive, then {\tt 1}; if \[EXPR\] is zero,
then {\tt 0}; otherwise {\tt -1}.

\item
\[random(EXPR)\].  The value is a {\tt number} selected at random in the interval
from {\tt 0} to the value of \[EXPR\], inclusive.
There has been no statistical study made of the generators.
Don't depend on them for highly sensitive work.

\item
\[randomize(EXPR)\].
If EXPR is an {\tt integer},
this resets the random number generator.
This may be used to re-create a sequence of random numbers.
On some systems, a non-integer argument resets the random number
generator in an uncontrolled fashion.
\end{enumerate}


\item
In each of the following, both occurrences of \[EXPR\] 
must evaluate to {\tt integer},
{\tt floating\_\,point}, or {\tt string}.  
The value of the function is the value of the
mathematical function in the same type as was the values of the two occurrences
of \[EXPR\].

\begin{enumerate}
\item
\[max(EXPR,EXPR)\].

\item
\[min(EXPR,EXPR)\].
\end{enumerate}
\end{enumerate}



\subsection{Type Testers.}

In each of the following, the value of \[EXPR\] can be any ISETL data type.
The function is the test for the value of
\[EXPR\] being the type indicated.

\begin{enumerate}

\item
\[is\_\,atom(EXPR)\].

\item
\[is\_\,boolean(EXPR)\].

\item
\[is\_\,integer(EXPR)\].

\item
\[is\_\,file(EXPR)\].

\item
\[is\_\,floating(EXPR)\].

\item
\[is\_\,func(EXPR)\].

\item
\[is\_\,map(EXPR)\].

\item
\[is\_\,number(EXPR)\] -- {\tt true} for {\tt integer} and 
{\tt floating\_\,point}.

\item
\[is\_\,set(EXPR)\].

\item
\[is\_\,string(EXPR)\].

\item
\[is\_\,tuple(EXPR)\].

\item
\[is\_\,om(EXPR)\].

\item
\[is\_\,defined(EXPR)\].  Negation of \[is\_\,om\].
\end{enumerate}



\subsection{Input/Output Functions.}

\begin{enumerate}
\item
In each of the following functions,
the value of \[EXPR\] must be a {\tt string} that
is a file name consistent with the operating system's naming conventions.
The value of the function has ISETL type {\tt file}
and may be in \[read\]...\[from\]... and \[print\]...\[to\]...
statements to refer to that file.

\begin{enumerate}
\item
\[openr(EXPR)\].  If the file named by the value of \[EXPR\] exists,
then it is opened for reading, and the value of the function 
is of type {\tt file}.
If the file named by the value of \[EXPR\] does not exist,
then the value of the function is \[OM\].

\item
\[openw(EXPR)\].  If the file named by the value of \[EXPR\] does not exist,
then it is created by the operating system externally to ISETL.
This file is opened for writing from the beginning,
so that anything previously in the file is destroyed.
The value of the function is of type {\tt file}.

\item
\[opena(EXPR)\].  The same as \[openw(EXPR)\] except that if the file exists
its contents are not destroyed.
Anything that is written is appended to the file.
\end{enumerate}


\item
In the following function, the value of 
\[EXPR\] must be of type {\tt file}.  The
file specified by this value is closed.  Output files must be closed to
guarantee that all output has been stored by the operating system.  All
files are closed automatically when ISETL is exited.
There is usually a system-imposed limit on the number of files
that may be open at one time, however, so it is a good idea to close files
when finished using them.

\begin{enumerate}
\item
\[close(EXPR)\].  The value of the function is \[OM\].
\end{enumerate}


\item
In the following function the value of \[EXPR\]  must be of type {\tt file}.

\begin{enumerate}

\item
\[eof(EXPR)\].  Test for having read past the end of an external file.
\end{enumerate}
\end{enumerate}



\subsection{Miscellaneous.}

\begin{enumerate}


\item
\[abs(EXPR)\].  If the value of \[EXPR\] is 
{\tt integer} or {\tt floating\_\,point}, then
the value of the function is the standard absolute value.  

\item
\[ord(EXPR)\].
The inverse of {\tt char}.
\[EXPR\] must be a {\tt string} of length 1.

\item
\[font(EXPR,EXPR)\].
{\em Macintosh version only.}
Both arguments should be {\tt integer}.
The first controls the font, the second the point size.
The relation between numbers and fonts is dependent on the fonts
loaded, so you need to experiment.
If an argument is not an {\tt integer}, that parameter is unchanged.
The result is a pair, where the first element is the old font and the
second element is the old size.
\end{enumerate}



\section{Precedence Rules}

\begin{itemize}
\item
Operators are listed from highest priority to lowest
priority.
\item
Operators are left associative unless otherwise indicated.
\item
``nonassociative'' means that you cannot use two operators
on that line without parentheses.
\end{itemize}
\begin{center}
\begin{tabular}{l l}
    \[CALL\]& \begin{tabular}{l}	anything that is\\
               a call	to a function\\
               -- {\tt func}, {\tt tuple}, {\tt string}, {\tt  map}, etc.\\
               \end{tabular}\\
    \[\#\]\\
    \[?\]&       nonassociative\\
    \[\%\]&       nonassociative\\
    \[**\]&      right associative\\
    \[* / mod div\]\\
    \[+ - with less\]\\
    \[INFIX .\]\\
    \[in notin subset \]\\
    \[< <= = /= > >=\] &     nonassociative\\
    \[not\]\\
    \[and\]\\
    \[or\]\\
    \[impl\]\\
\end{tabular}
\end{center}

\section {Directives}

There are a number of directives that can be given to ISETL to modify
its behavior.

On the command line, \[-s\] indicates {\em silent mode}.
In silent mode, the header and all prompts are supressed.
This is useful when using ISETL as a filter. This feature is not available on
the Macintosh version.)

The rest of the directives are \[!\] commands.

\begin{enumerate}

\item
\[!quit\] -- exit ISETL.

\item
\[!include <filename>\] -- Replace \[<filename>\] with a file/pathname
according to the rules of your operating system.
ISETL will insert your file.

\item
\[!clear\] -- throw away all input back to the last single prompt.

\item
\[!edit\] -- edit all the input back to the last single prompt.

\item
\[!echo [ on | off ]\] -- When on, all input is echoed.
This is particularly useful when trying to find a syntax error in an
\[!include\] file or input for a {\tt read}.
It is also useful for pedagogical purposes, as it can be used to 
interleave input and output.

\item
\[!memory\] -- shows how much memory has been allocated.

\item
\[!memory nnn\] -- increase the legal upper bound to \[nnn\].

\item
\[!code [ on | off ]\] -- When on, you get a pseudo-assembly listing
for the program.  Default is off.

\item
\[!trace [ on | off ]\] -- When on, you get an execution trace, using
the same notation as \[!code\].
When desperate, this can be used to watch the execution of your
program.
Really intended for debugging ISETL.
Default is off.

\item
\[!ids\] -- Lists all identifiers which have been defined.
\end{enumerate}

\section{Editor}

\begin{enumerate}

\begin{sloppypar}
\item
The user can edit whatever has been entered since the beginning of the
current syntactic object,
in response to a syntax error message, or if the user wants to change
something previously typed.
If you prefer to start again,
``\[!clear\]'' will clear the typing buffer and allow you to start the
input afresh.
\end{sloppypar}

\item
When the editor is invoked
(by typing ``\[!edit\]''), the user is prompted for the string that is to
be modified.  The user types the desired string, and the editor finds its
first occurrence in the lines being edited.

\item
The user is then prompted for the replacement of this string.  When it is
entered, the change is made.

\item
The process repeats until the user enters a blank search line,
at which time control is returned to ISETL.
\end{enumerate}

\newpage
\section{Error Messages}

The following list of error messages is given in two columns.  The first is
the message as it is printed to standard output, and the second gives a
brief explanation of the meaning of the message.

\begin{tabular}{l l}
*& used for self explanatory messages\\
internal& messages the user should never see\\
operator& messages that report bad args to the operator\\
\end{tabular}

\begin{tabular}{l l}
RT Message	&		Explanation\\
\\
'\#'&				operator\\
And&				operator\\
Assignment&			operator\\
Bad arg to mcPrint&		internal\\
Bad args in low,next..high&	*\\
Bad args in low..high&	*\\
Bad modulus&			operator mod\\
Bad selector to modify&		lhs and selector incompatible\\
Bad slice assignment&		slice on lhs out of range\\
Bounds must be integer&		*\\
Cannot edit except at top level&Edit not permitted within an include\\
Cannot SMap&			Cannot perform selection \\
Cannot MMap&			Cannot perform selection \\
Cannot Slice&			Cannot perform selection \\
Cnt2&				bad args to \[x..y\]\\
Cnt3&				bad args to \[x,y..z\]\\
Div&				operator\\
Divide by zero&			*\\
Exp&				operator\\
From&				operator\\
Fromb&				operator\\
Frome&				operator\\
IC2&				bad args to iterator over \[x..z\]\\
IC3&				bad args to iterator over \[x,y..z\]\\
Impl&				operator\\
In&				operator\\
Index $<$ 1&			*\\
\end{tabular}

\vspace{\fill}
\begin{tabular}{l l}
Index out of bounds&		*\\
Input must be an expression&	*\\
Iter\_\,Next&			internal\\
Less&				operator\\
Lower bound $<$ 1&		*\\
MMap&				bad args to iterator for MMap\\
MMap/Str&			bad args to iterator for MMap\\
MMap/Tuple&			bad args to iterator for MMap\\
Minus&				operator\\
Mk\_\,Iter&			bad LHS for iterator\\
Mod&				operator\\
Negate&				operator (unary \[-\])\\
Negative slice&			*\\
Non-bool to Br\_\,False&	May occur in \[if\], \[while\], \[and\], \[or\]\\
Non-bool to Br\_\,True&		May occur in \[if\], \[while\], \[and\], \[or\]\\
Non-integer index to string&	*\\
Non-integer index to tuple&	*\\
Not&				operator\\
Only one level of selection allowed&Limitation on modification of funcs\\
Or&				operator\\
Order Relation&			incomparable args to \[<\],\[>\],\[<=\],\[>=\]\\
Plus&				operator\\
RHS of MMap must be a set&	\[f\{x\}\], \[f\]  not a set of ordered pairs\\
Return at top level&		*\\
Set Coersion&			internal\\
Slash&				operator\\
Slice out of bounds&		*\\
Stack Overflow&			*\\
Stack Underflow&		* internal\\
String index too small&		*\\
String requires integer index&	*\\
Subset&				operator\\
Times&				operator\\
Top level return not allowed&	*\\
Tuple index too small	&	*\\
Tuple requires integer index&	*\\
With&				operator\\
\end{tabular}


\end{document}
