%% Oh Emacs, this is a -*- Lisp -*- file despite apperance.
\documentclass{book}
\usepackage{axiom}
\usepackage{graphicx}
% struggle with latex figure-floating behavior
\renewcommand\floatpagefraction{.9}
\renewcommand\topfraction{.9}
\renewcommand\bottomfraction{.9}
\renewcommand\textfraction{.1}
\setcounter{totalnumber}{50}
\setcounter{topnumber}{50}
\setcounter{bottomnumber}{50}

\begin{document}
\begin{titlepage}
\center{\includegraphics{ps/axiomFront.ps}}
\vskip 0.1in
\includegraphics{ps/bluebayou.ps}\\
\vskip 0.1in
{\Huge{The 30 Year Horizon}}
\vskip 0.1in
$$
\begin{array}{lll}
Manuel\ Bronstein      & William\ Burge   & Timothy\ Daly \\
James\ Davenport       & Michael\ Dewar   & Martin\ Dunstan \\
Albrecht\ Fortenbacher & Patrizia\ Gianni & Johannes\ Grabmeier \\
Jocelyn\ Guidry        & Richard\ Jenks   & Larry\ Lambe \\
Michael\ Monagan       & Scott\ Morrison  & William\ Sit \\
Jonathan\ Steinbach    & Robert\ Sutor    & Barry\ Trager \\
Stephen\ Watt          & Jim\ Wen         & Clifton\ Williamson
\end{array}
$$
\center{\large{VOLUME 5: THE AXIOM INTERPRETER}}
\end{titlepage}
\pagenumbering{roman}
\begin{verbatim}
The Blue Bayou image Copyright (c) 2004 Jocelyn Guidry

Portions Copyright (c) 2004 Martin Dunstan

Portions Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
All rights reserved.

This book and the Axiom software is licensed as follows:

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    - Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

    - Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the
      distribution.

    - Neither the name of The Numerical ALgorithms Group Ltd. nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

\end{verbatim}
\tableofcontents
\vfill
\eject
\setlength{\parindent}{0em}
\setlength{\parskip}{1ex}
{\Large{\bf New Foreword}}
\vskip .25in

On October 1, 2001 Axiom was withdrawn from the market and ended
life as a commercial product.
On September 3, 2002 Axiom was released under the Modified BSD
license, including this document.
On August 27, 2003 Axiom was released as free and open source
software available for download from the Free Software Foundation's
website, Savannah.

Work on Axiom has had the generous support of the Center for 
Algorithms and Interactive Scientific Computation (CAISS) at
City College of New York. Special thanks go to Dr. Gilbert 
Baumslag for his support of the long term goal.

The online version of this documentation is roughly 1000 pages.
In order to make printed versions we've broken it up into three
volumes. The first volume is tutorial in nature. The second volume
is for programmers. The third volume is reference material. We've
also added a fourth volume for developers. All of these changes
represent an experiment in print-on-demand delivery of documentation.
Time will tell whether the experiment succeeded.

Axiom has been in existence for over thirty years. It is estimated to
contain about three hundred man-years of research and has, as of
September 3, 2003, 143 people listed in the credits. All of these
people have contributed directly or indirectly to making Axiom
available.  Axiom is being passed to the next generation. I'm looking
forward to future milestones.

With that in mind I've introduced the theme of the ``30 year horizon''.
We must invent the tools that support the Computational Mathematician
working 30 years from now. How will research be done when every bit of
mathematical knowledge is online and instantly available? What happens
when we scale Axiom by a factor of 100, giving us 1.1 million domains?
How can we integrate theory with code? How will we integrate theorems
and proofs of the mathematics with space-time complexity proofs and
running code? What visualization tools are needed? How do we support
the conceptual structures and semantics of mathematics in effective
ways? How do we support results from the sciences? How do we teach
the next generation to be effective Computational Mathematicians?

The ``30 year horizon'' is much nearer than it appears.

\vskip .25in
%\noindent
Tim Daly\\
CAISS, City College of New York\\
November 10, 2003 ((iHy))
\vfill
\eject
\pagenumbering{arabic}
\setcounter{chapter}{0} % Chapter 1
\chapter{The Interpreter}
\section{Star Global Variables}
\begin{tabular}{lll}
NAME                        & SET              & USE \\
*eof*                       & ncTopLevel       & \\
*features*                  &                  & restart \\
*package*                   &                  & restart \\
*standard-input*            &                  & ncIntLoop \\
*standard-output*           &                  & ncIntLoop \\
*top-level-hook*            & set-restart-hook & \\
\end{tabular}

\subsection{*eof*}
The [[*eof*]] variable is set to [[NIL]] in [[ncTopLevel]].
\subsection{*features*}
The [[*features*]] variable from common lisp is tested for the presence
of the [[:unix]] keyword. Apparently this controls the use of Saturn,
a previous Axiom frontend. The Saturn frontend was never released as
open source and so this test and the associated variables are probably
not used.

\subsection{*package*}
The [[*package*]] variable, from common lisp, is set in [[restart]]
to the [[BOOT]] package where the intepreter lives.
\subsection{*standard-input*}
The [[*standard-input*]] common lisp variable is used to set the 
[[curinstream]] variable in [[ncIntLoop]]. 

This variable is an argument to [[serverReadLine]] in
the [[intloopReadConsole]] function.

\subsection{*standard-output*}
The [[*standard-output*]] common lisp variable is used to set the 
[[curoutstream]] variable in [[ncIntLoop]].

\subsection{*top-level-hook*}
The [[*top-level-hook*]] common lisp variable contains the name of
a function to invoke when an image is started. In our case it is
called [[restart]]. This is the entry point to the Axiom interpreter.

\section{Dollar Global Variables}
\begin{tabular}{lll}
NAME                         & SET                 & USE \\
\$boot                       & ncTopLevel          & \\
coerceFailure                &                     & runspad \\
curinstream                  & ncIntLoop           & \\
curoutstream                 & ncIntLoop           & \\
vmlisp::\$current-directory  & restart             & \\
                             & reroot              & \\
\$currentLine                & restart             & removeUndoLines \\
\$dalymode                   &                     & intloopReadConsole \\
\$defaultMsgDatabaseName     & reroot              & \\
\$directory-list             & reroot              & \\
\$displayStartMsgs           &                     & restart \\
\$e                          & ncTopLevel          & \\
\$erMsgToss                  & SpadInterpretStream & \\
\$fn                         & SpadInterpretStream & \\
\$frameRecord                & initvars            & \\
                             & clearFrame          & \\
                             & undoSteps           & undoSteps \\
                             & recordFrame         & recordFrame \\
\$HiFiAccess                 & initHist            & historySpad2Cmd \\
                             & historySpad2Cmd     & \\
                             &                     & setHistoryCore \\
\$HistList                   & initHist            & \\
\$HistListAct                & initHist            & \\
\$HistListLen                & initHistList        & \\
\$HistRecord                 & initHistList        & \\
\$historyDirectory           &                     & makeHistFileName \\
                             &                     & makeHistFileName \\
\$historyFileType            & initvars           & histInputFileName \\
\$inclAssertions             & SpadInterpretStream & \\
\$inLispVM                   & spad                & \\
\$InteractiveFrame           & restart             & ncTopLevel \\
                             & undo                & recordFrame \\
                             & undoSteps           & undoSteps \\
                             &                     & reportUndo \\
\$InteractiveMode            & ncTopLevel          & \\
\$internalHistoryTable       & initvars            & \\
\$interpreterFrameName       & initializeInterpreterFrameRing & \\
\$interpreterFrameRing       & initializeInterpreterFrameRing & \\
\$InitialModemapFrame        &                     & makeInitialModemapFrame \\
\$intRestart                 &                     & intloop \\
\$intTopLevel                & intloop             & \\
\$IOindex                    & restart             & historySpad2Cmd \\
                             & removeUndoLines     & undoCount \\
\$lastPos                    & SpadInterpretStream & \\
\$libQuiet                   & SpadInterpretStream & \\
\$library-directory-list     & reroot              & \\
\$msgDatabaseName            & reroot              * \\
\$ncMsgList                  & SpadInterpretStream & \\
\$newcompErrorCount          & SpadInterpretStream & \\
\$newcompMode                & SpadInterpretStream & \\
\$newspad                    & ncTopLevel          & \\
\$nopos                      &                     & SpadInterpretStream \\
\$okToExecuteMachineCode     & SpadInterpretStream & \\
\$oldHistoryFileName         & initvars            & oldHistFileName \\
\$openServerIfTrue           & restart             & restart \\
                             & spad-save           & \\
                             & initvars            & \\
\$options                    &                     & history \\
                             & historySpad2Cmd     & historySpad2Cmd \\
                             &                     & undo \\
\$previousBindings           & initvars            & \\
                             & clearFrame          & \\
                             & recordFrame         & recordFrame \\
\$printLoadMsgs              & restart             & \\
\$PrintCompilerMessageIfTrue & spad                & \\
\$promptMsg                  & SpadInterpretStream & \\
\$relative-directory-list    &                     & reroot \\
\$relative-library-directory-list &                & reroot \\
\$reportUndo                 & initvars            & diffAlist \\
\$shoeReadLineFunction       & SpadInterpretStream & \\
\$spad                       & ncTopLevel          & \\
\$spadroot                   & reroot              & initroot \\
                             &                     & make-absolute-filename \\
                             &                     & reroot \\
\$SpadServer                 & restart             & \\
\$SpadServerName             & initvars            & restart \\
\$systemCommandFunction      & SpadInterpretStream & \\
top\_level                   &                     & runspad \\
\$quitTag                    &                     & runspad \\
\$useInternalHistoryTable    & initvars            & initHist \\
                             & setHistoryCore      & setHistoryCore \\
\$undoFlag                   & initvars            & recordFrame \\
\end{tabular}

\subsection{\$boot}
The [[$boot]] variable is set to [[NIL]] in [[ncTopLevel]].

\subsection{coerceFailure}
The [[coerceFailure]] symbol is a catch tag used in [[runspad]]
to catch an exit from [[ncTopLevel]].

\subsection{curinstream}
The [[curinstream]] variable is set to the value of the 
[[*standard-input*]] common lisp
variable in [[ncIntLoop]]. While not using the
``dollar'' convention this variable is still ``global''.

\subsection{curinstream}
The [[curoutstream]] variable is set to the value of the 
[[*standard-output*]] common lisp variable in [[ncIntLoop]].
While not using the ``dollar'' convention this variable is still ``global''.

\subsection{vmlisp::\$current-directory}
When running in Lucid Common Lisp ([[:lucid]]) on an IBM/370 mainframe
([[:ibm/370]]) this variable is used in place of the 
[[*default-pathname-defaults*]] common lisp variable. 
Otherwise this variable is
set to the empty string in [[restart]]. 

Notice that the variable [[*default-pathname-defaults*]] is a Common
Lisp standard variable with implementation defined meaning.
Typically, its value is an object that represents the directory from
where the Lisp image has been started.

The [[reroot]] function sets this variable to the value of
[[$spadroot]] which itself has the value of the argument to the
[[reroot]] function. Since the argument to the [[reroot]] function is
an string which represents an absolute pathname pointing to OpenAxiom the
net result is that the [[$current-directory]] is set to point to the
shell [[AXIOM]] variable.

So during execute both [[$current-directory]] and [[$spadroot]] reflect
the value of the [[AXIOM]] shell variable.

\subsection{\$currentLine}
The [[$currentLine]] line is set to [[NIL]] in [[restart]].
It is used in [[removeUndoLines]] in the undo mechanism.

\subsection{\$dalymode}
The [[$dalymode]] variable is used in a case statement in 
[[intloopReadConsole]]. This variable can be set to any non-nil
value. When not nil the interpreter will send any line that begins
with an ``[[(]]'' to be sent to the underlying lisp. This is useful
for debugging Axiom. The normal value of this variable is [[NIL]].

This variable was created as an alternative to prefixing every lisp
command with [[)lisp]]. When doing a lot of debugging this is tedious
and error prone. This variable was created to shortcut that process.
Clearly it breaks some semantics of the language accepted by the
interpreter as parens are used for grouping expressions.

\subsection{\$defaultMsgDatabaseName}
The [[$defaultMsgDatabaseName]] is the absolute path to the 
[[s2-us.msgs]] file which contains all of the english language
messages output by the system.

\subsection{\$directory-list}
The [[$directory-list]] is a list of absolute directory names.
These names are made absolute by mapping the [[make-absolute-filename]]
over the variable [[$relative-directory-list]].

\subsection{\$displayStartMsgs}
The [[$displayStartMsgs]] variable is used in [[restart]] but is not
set so this is likely a bug.

\subsection{\$e}
The [[$e]] variable is set to the value of
[[$InteractiveFrame]] which is set in [[restart]] to the value of the
call to the [[makeInitialModemapFrame]] function. This function simply
returns a copy of the variable [[$InitialModemapFrame]].

Thus [[$e]] is a copy of the variable [[$InitialModemapFrame]].

This variable is used in the undo mechanism.

\subsection{\$erMsgToss}
The [[$erMsgToss]] variable is set to [[NIL]] in [[SpadInterpretStream]].

\subsection{\$fn}
The [[$fn]] variable is set in [[SpadInterpretStream]]. It is set to
the second argument which is a list. It appears that this list has the
same structure as an argument to the LispVM [[rdefiostream]] function.

\subsection{\$frameRecord}
[[$frameRecord = [delta1, delta2,... ] ]] where
[[delta(i)]] contains changes in the ``backwards'' direction.
Each [[delta(i)]] has the form [[((var . proplist)...)]] where
proplist denotes an ordinary proplist. For example, an entry
of the form [[((x (value) (mode (Integer)))...)]] indicates that
to undo 1 step, [[x]]'s value is cleared and its mode should be set
to [[(Integer)]].

A [[delta(i)]] of the form [[(systemCommand . delta)]] is a special
delta indicating changes due to system commands executed between
the last command and the current command. By recording these deltas
separately, it is possible to undo to either BEFORE or AFTER
the command. These special [[delta(i)]]s are given ONLY when a
a system command is given which alters the environment.

Note: [[recordFrame('system)]] is called before a command is executed, and
[[recordFrame('normal)]] is called after (see processInteractive1).
If no changes are found for former, no special entry is given.

This is part of the undo mechanism.

\subsection{\$HiFiAccess}
The [[$HiFiAccess]] is set by [[initHist]] to [[T]]. It is a flag
used by the history mechanism to record whether the history function
is currently on. It can be reset by using the axiom
command
\begin{verbatim}
  )history off
\end{verbatim}
It appears that the name means ``History File Access''.

The [[$HiFiAccess]] variable is used by [[historySpad2Cmd]] to check
whether history is turned on. [[T]] means it is, [[NIL]] means it is not.

\subsection{\$HistList}
Thie [[$HistList]] variable is set by [[initHistList]] to an initial
value of [[NIL]] elements. The last element of the list is smashed to
point to the first element to make the list circular.
This is a circular list of length [[$HistListLen]].

\subsection{\$HistListAct}
The [[$HistListAct]] variable is set by [[initHistList]] to [[0]].
This variable holds the actual number of elements in the history list.
This is the number of ``undoable'' steps.

\subsection{\$HistListLen}
The [[$HistListLen]] variable is set by [[initHistList]] to [[20]].
This is the length of a circular list maintained in the variable
[[$HistList]].

\subsection{\$HistRecord}
The [[$HistRecord]] variable is set by [[initHistList]] to [[NIL]].
[[$HistRecord]] collects the input line, all variable bindings
and the output of a step, before it is written to the file named by
the function [[histFileName]].

\subsection{\$historyFileType}
The [[$historyFileType]] is set at load time by a call to 
[[initvars]] to a value of ``[[axh]]''. It appears that this
is intended to be used as a filetype extension.
It is part of the history mechanism. It is used in [[makeHistFileName]]
as part of the history file name.

\subsection{\$inclAssertions}
The [[$inclAssertions]] is set 
in the function [[SpadInterpretStream]] to the list [[(aix |CommonLisp|)]]

\subsection{\$internalHistoryTable}
The [[$internalHistoryTable]] variable is set at load time by a call to
[[initvars]] to a value of [[NIL]].
It is part of the history mechanism.

\subsection{\$interpreterFrameName}
The [[$interpreterFrameName]] variable, set in 
[[initializeInterpreterFrameRing]] to the constant
[[initial]] to indicate that this is the initial (default) frame.

Frames are structures that capture all of the variables defined in a
session. There can be multiple frames and the user can freely switch
between them. Frames are kept in a ring data structure so you can 
move around the ring.

\subsection{\$interpreterFrameRing}
The [[$interpreterFrameRing]] is set to a pair whose car is set to
the result of [[emptyInterpreterFrame]]

\subsection{\$InitialModemapFrame}
This variable is copied and returned by the function 
[[makeInitialModemapFrame]]. There is no initial value so this
is probably a bug.

\subsection{\$inLispVM}
The [[$inLispVM]] is set to [[NIL]] in [[spad]]. LispVM is a
non-common lisp that runs on IBM/370 mainframes. This is probably dead
code.  It appears that this list has the same structure as an argument
to the LispVM [[rdefiostream]] function.

\subsection{\$InteractiveFrame}
The [[$InteractiveFrame]] is set in [[restart]] to the value of the
call to the [[makeInitialModemapFrame]] function. This function simply
returns a copy of the variable [[$InitialModemapFrame]]

\subsection{\$InteractiveMode}
The [[$InteractiveMode]] is set to [[T]] in [[ncTopLevel]].

\subsection{\$intRestart}
The [[$intRestart]] variable is used in [[intloop]] but has no value.
This is probably a bug. While the variable's value is unchanged the
system will continually reenter the [[SpadInterpretStream]] function.

\subsection{\$intTopLevel}
The [[$intTopLevel]] is a catch tag. Throwing to this tags which is
caught in the [[intloop]] will 
restart the [[SpadInterpretStream]] function.

\subsection{\$IOindex}
The [[$IOindex]] index variable is set to [[1]] in [[restart]].
This variable is used in the [[historySpad2Cmd]] function in the
history mechanism. It is set in the [[removeUndoLines]] function
in the undo mechanism.

This is used in the undo mechanism in function [[undoCount]]
to compute the number of undos. You can't undo more actions then
have already happened.

\subsection{\$lastPos}
The [[$lastPos]] variable is set in [[SpadInterpretStream]]
to the value of the [[$nopos]] variable.
Since [[$nopos]] appears to have no value
this is likely a bug.

\subsection{\$libQuiet}
The [[$libQuiet]] variable is set to the third argument of the
[[SpadInterpretStream]] function. This is passed from [[intloop]]
with the value of [[T]]. This variable appears to be intended to
control the printing of library loading messages which would need
to be suppressed if input was coming from a file.

\subsection{\$library-directory-list}
The [[$library-directory-list]] variable is set by [[reroot]] by
mapping the function [[make-absolute-filename]] across the 
[[$relative-library-directory-list]] variable which is not yet set so this
is probably a bug.

\subsection{\$msgDatabaseName}
The [[$msgDatabaseName]] is set to [[NIL]] in [[reroot]].

\subsection{\$ncMsgList}
The [[$ncMsgList]] is set to [[NIL]] in [[SpadInterpretStream]].

\subsection{\$newcompErrorCount}
The [[$newcompErrorCount]] is set to [[0]] in [[SpadInterpretStream]].

\subsection{\$newcompMode}
The [[$newcompMode]] is set to [[NIL]] in [[SpadInterpretStream]].

\subsection{\$newspad}
The [[$newspad]] is set to [[T]] in [[ncTopLevel]].

\subsection{\$nopos}
The [[$nopos]] variable is used in [[SpadInterpretStream]] but does
not appear to have a value and is likely a bug.

\subsection{\$oldHistoryFileName}
The [[$oldHistoryFileName]] is set at load time by a call to 
[[initvars]] to a value of ``[[last]]''. 
It is part of the history mechanism. It is used in the function
[[oldHistFileName]] and [[restoreHistory]].

\subsection{\$okToExecuteMachineCode}
The [[$okToExecuteMachineCode]] is set to [[T]] in [[SpadInterpretStream]].

\subsection{\$options}
The [[$options]] variable is tested by the [[history]] function.
If it is [[NIL]] then output the message 
\begin{verbatim}
  You have not used the correct syntax for the history command.
  Issue )help history for more information.
\end{verbatim}

The [[$options]] variable is tested in the [[historySpad2Cmd]] function.
It appears to record the options that were given to a spad command on
the input line. The function [[selectOptionLC]] appears to take a list
off options to scan.

This variable is not yet set and is probably a bug.

\subsection{\$previousBindings}
The [[$previousBindings]] is a copy of the 
[[CAAR $InteractiveFrame]]. This is used to
compute the [[delta(i)]]s stored in [[$frameRecord]].
This is part of the undo mechanism.

\subsection{\$PrintCompilerMessageIfTrue}
The [[$PrintCompilerMessageIfTrue]] variable is set to [[NIL]] in [[spad]].

\subsection{\$openServerIfTrue}
The [[$openServerIfTrue]] is tested in [[restart]] before it has been
set (and is thus a bug). It appears to control whether the interpreter
will be used as an open server, probably for OpenMath use.

If an open server is not requested then this variable to [[NIL]]

\subsection{\$promptMsg}
The [[$promptMsg]] variable is set to the constant [[S2CTP023]]. This 
constant points to a message in [[src/doc/msgs/s2-us.msgs]]. This message
does nothing but print the argument value.

\subsection{\$relative-directory-list}
The [[$relative-directory-list]] is used in [[reroot]] to create 
[[$directory-list]] which is a list of absolute directory names.
It is not yet set and is probably a bug.

\subsection{\$relative-library-directory-list}
The [[$relative-library-directory-list]] is used in [[reroot]] to create
a list of absolute directory names from [[$library-directory-list]] (which is 
It is not yet set and is probably a bug).

\subsection{\$reportUndo}
The [[$reportUndo]] variable is used in [[diffAlist]]. It was not normally
bound but has been set to [[T]] in [[initvars]]. If the variable is set
to [[T]] then we call [[reportUndo]].

It is part of the undo mechanism.

\subsection{\$shoeReadLineFunction}
The [[$shoeReadLineFunction]] is set in [[SpadInterpretStream]]
to point to the 
[[serverReadLine]] 

\subsection{\$spadroot}
The [[$spadroot]] variable is the internal name for the [[AXIOM]]
shell variable. 

The [[$spadroot]] variable is set in [[reroot]] to the value of the
argument. The argument is expected to be a directory name. 

The [[$spadroot]] variable is tested in [[initroot]].

The [[$spadroot]] variable is used by the function 
[[make-absolute-filename]]. It concatenates this variable to the 
front of a relative pathname to make it absolute.
\subsection{\$spad}
The [[$spad]] variable is set to [[T]] in [[ncTopLevel]].

\subsection{\$SpadServer}
If an open server is not requested then this variable to [[T]].
It has no value before this time (and is thus a bug).

\subsection{\$SpadServerName}
The [[$SpadServerName]] is passed to the [[openServer]] function, if the
function exists. 

\subsection{\$systemCommandFunction}
The [[$systemCommandFunction]] is set in [[SpadInterpretStream]]
to point to the function
[[InterpExecuteSpadSystemCommand]].

\subsection{top\_level}
The [[top\_level]] symbol is a catch tag used in [[runspad]]
to catch an exit from [[ncTopLevel]].

\subsection{\$quitTag}
The [[$quitTag]] is used as a variable in a [[catch]] block. 
It appears that it can be thrown somewhere below [[ncTopLevel]].

\subsection{\$useInternalHistoryTable}
The [[$useInternalHistoryTable]] variable is set at load time by a call to
[[initvars]] to a value of [[NIL]]. It is part of the history mechanism.

\subsection{\$undoFlag}
The [[$undoFlag]] is used in [[recordFrame]] to decide whether to do
undo recording. It is initially set to [[T]] in [[initvars]].
This is part of the undo mechanism.

\chapter{Starting Axiom}
Axiom starts by invoking a function value of the lisp symbol
[[*top-level-hook*]]. The function invocation path to from this
point until the prompt is approximates (skipping initializations):
\begin{verbatim}
  lisp -> restart
       -> |spad|
       -> |runspad|
       -> |ncTopLevel|
       -> |ncIntLoop|
       -> |intloop|
       -> |SpadInterpretStream|
       -> |intloopReadConsole|
\end{verbatim}
The [[|intloopReadConsole|]] function does tail-recursive calls to
itself (don't break this) and never exits.
\section{Variables Used}
\section{Data Structures}
\section{Functions}
\subsection{defun set-restart-hook}
When a lisp image containing code is reloaded there is a hook to
allow a function to be called. In our case it is the [[restart]]
function which is the entry to the Axiom interpreter.
<<defun set-restart-hook>>=
(defun set-restart-hook ()
  #+KCL (setq system::*top-level-hook* 'restart)
  #+Lucid (setq boot::restart-hook 'restart)
  'restart
 )

@
\subsection{defun restart}
The restart function is the real root of the world. It sets up memory
if we are working in a GCL/akcl version of the system. It sets the
current package to be the ``BOOT'' package which is the standard
package in which the interpreter runs. It calls initroot \cite{1}
to set the \$spadroot variable (usually the \$AXIOM variable).

The [[compiler::*compile-verbose*]] flag has been set to nil globally.
We do not want to know about the microsteps of GCL's compile facility.

The [[compiler::*suppress-compiler-warnings*]] flag has been set to t.
We do not care that certain generated variables are not used.

The [[compiler::*suppress-compiler-notes*]] flag has been set to t.
We do not care that tail recursion occurs.
<<defun restart>>=
(defun restart ()
#+:akcl
  (init-memory-config :cons 500 :fixnum 200 :symbol 500 :package 8
    :array 400 :string 500 :cfun 100 :cpages 3000 :rpages 1000 :hole 2000)
#+:akcl (setq compiler::*compile-verbose* nil)
#+:akcl (setq compiler::*suppress-compiler-warnings* t)
#+:akcl (setq compiler::*suppress-compiler-notes* t)
#-:CCL
  (in-package "BOOT")
#+:CCL
  (setq *package* (find-package "BOOT"))
#+:CCL (setpchar "") ;; Turn off CCL read prompts
#+(OR :akcl :CCL) (initroot)
#+:akcl (system:gbc-time 0)
#+:akcl
  (when (and $openServerIfTrue (fboundp '|openServer|))
   (prog (os)
    (setq os (|openServer| $SpadServerName))
    (if (zerop os) 
     (progn 
      (setq $openServerIfTrue nil) 
      (setq |$SpadServer| t)))))
;; We do the following test at runtime to allow us to use the same images
;; with Saturn and Sman.  MCD 30-11-95
#+:CCL
  (when 
     (and (memq :unix *features*) $openServerIfTrue (fboundp '|openServer|))
   (prog (os)
    (setq os (|openServer| $SpadServerName))
    (if (zerop os) 
     (progn 
      (setq $openServerIfTrue nil) 
      (setq |$SpadServer| t)))))
  (setq |$IOindex| 1)
  (setq |$InteractiveFrame| (|makeInitialModemapFrame|))
#+(and :lucid :ibm/370)
  (setq vmlisp::$current-directory "")
#-(and :lucid :ibm/370)
  (setq vmlisp::$current-directory
     (make-directory *default-pathname-defaults*))
  (|loadExposureGroupData|)
  (|statisticsInitialization|)
  (|initHist|)
  (|initializeInterpreterFrameRing|)

  (when |$displayStartMsgs| 
   (|spadStartUpMsgs|))
  (setq |$currentLine| nil)
  (restart0)
  (|readSpadProfileIfThere|)
  (|spad|))

@

\subsection{defun SpadInterpretStream}
The [[SpadInterpretStream]] function takes three arguments
\begin{list}{}
\item [[str]] This is passed as an argument to [[intloopReadConsole]]
\item [[source]] This is the name of a source file but appears not
to be used. It is set to the list [[(tim daly ?)]].
\item [[interactive?]] If this is false then various messages are 
suppressed and input does not use piles. If this is true then the
library loading routines might output messages and piles are expected
on input (as from a file).
\end{list}


\section{Helper Functions}
\subsection{defun reclaim}
Call the garbage collector on various platforms.
<<defun reclaim>>=
#+abcl 
(defun reclaim () (ext::gc))
#+:allegro
(defun reclaim () (excl::gc t))
#+:CCL
(defun reclaim () (gc))
#+clisp
(defun reclaim () (#+lisp=cl ext::gc #-lisp=cl lisp::gc))
#+(or :cmulisp :cmu)
(defun reclaim () (ext:gc))
#+cormanlisp
(defun reclaim () (cl::gc))
#+(OR IBCL KCL GCL)
(defun reclaim () (si::gbc t))
#+lispworks 
(defun reclaim () (hcl::normal-gc))
#+Lucid
(defun reclaim () (lcl::gc))
#+sbcl
(defun reclaim () (sb-ext::gc))
@

\subsection{defun init-memory-config}
Austin-Kyoto Common Lisp (AKCL), now known as Gnu Common Lisp (GCL)
requires some changes to the default memory setup to run Axiom efficently.
This function performs those setup commands. 
<<defun init-memory-config>>=
(defun init-memory-config (&key
			   (cons 500)
			   (fixnum 200)
			   (symbol 500)
			   (package 8)
			   (array 400)
			   (string 500)
			   (cfun 100)
			   (cpages 3000)
			   (rpages 1000)
			   (hole 2000) )
  ;; initialize AKCL memory allocation parameters
  #+:AKCL
  (progn
    (system:allocate 'cons cons)
    (system:allocate 'fixnum fixnum)
    (system:allocate 'symbol symbol)
    (system:allocate 'package package)
    (system:allocate 'array array)
    (system:allocate 'string string)
    (system:allocate 'cfun cfun)
    (system:allocate-contiguous-pages cpages)
    (system:allocate-relocatable-pages rpages)
    (system:set-hole-size hole))
  #-:AKCL
  nil)

@
\subsection{defun initroot}
Sets up the system to use the {\bf AXIOM} shell variable if we can
and default to the {\bf \$spadroot} variable (which was the value
of the {\bf AXIOM} shell variable at build time) if we can't.
<<defun initroot>>=
(defun initroot (&optional (newroot (BOOT::|getEnv| "AXIOM")))
  (reroot (or newroot $spadroot (error "setenv AXIOM or (setq $spadroot)"))))

@
\subsection{defun loadExposureGroupData}
<<defun loadExposureGroupData>>=
#+:AKCL
(defun |loadExposureGroupData| ()
 (cond
  ((load "./exposed" :verbose nil :if-does-not-exist nil)
    '|done|)
  ((load (concat (system:getenv "AXIOM") "/algebra/exposed")
     :verbose nil :if-does-not-exist nil)
   '|done|)
  (t '|failed|) ))

#+:CCL
(defun |loadExposureGroupData| ()
 (cond
  ((load "./exposed.lsp" :verbose NIL :if-does-not-exist NIL) '|done|)
  ((load (concat (BOOT::|getEnv| "AXIOM") "/../../src/algebra/exposed.lsp") 
    :verbose nil :if-does-not-exist nil) '|done|)
  (t nil) ))

@
\subsection{make-absolute-filename}
Prefix a filename with the {\bf AXIOM} shell variable.
<<defun make-absolute-filename>>=
(defun make-absolute-filename (name)
 (concatenate 'string $spadroot name))

@

\subsection{defun reroot}
The reroot function is used to reset the important variables used by
the system. In particular, these variables are sensitive to the
{\bf AXIOM} shell variable. That variable is renamed internally to
be {\bf \$spadroot}. The {\bf reroot} function will change the
system to use a new root directory and will have the same effect
as changing the {\bf AXIOM} shell variable and rerunning the system
from scratch. Note that we have changed from the
NAG distribution back to the original form. If you need the NAG
version you can push {\bf :tpd} on the {\bf *features*} variable
before compiling this file. A correct call looks like:
\begin{verbatim}
(in-package "BOOT")
(reroot "/spad/mnt/${SYS}")
\end{verbatim}
where the [[${SYS}]] variable is the same one set at build time.
<<defun reroot>>=
(defun reroot (dir)
  (setq $spadroot dir)
  (setq $directory-list
   (mapcar #'make-absolute-filename $relative-directory-list))
  (setq $library-directory-list
   (mapcar #'make-absolute-filename $relative-library-directory-list))
  (setq |$defaultMsgDatabaseName|
	(pathname (make-absolute-filename "/share/msgs/s2-us.msgs")))
  (setq |$msgDatabaseName| ())
  (setq $current-directory $spadroot))

@
\subsection{defun statisticsInitialization}
<<defun statisticsInitialization>>=
(defun |statisticsInitialization| () 
 "initialize the garbage collection timer"
 #+:akcl (system:gbc-time 0)
 nil)

@
\chapter{The History Mechanism}
\section{)history}
\index{ugSysCmdhistory}

\index{history}


\par\noindent{\bf User Level Required:} interpreter

\par\noindent{\bf Command Syntax:}
\begin{list}{}
\item{\tt )history )on}
\item{\tt )history )off}
\item{\tt )history )write} {\it historyInputFileName}
\item{\tt )history )show [{\it n}] [both]}
\item{\tt )history )save} {\it savedHistoryName}
\item{\tt )history )restore} [{\it savedHistoryName}]
\item{\tt )history )reset}
\item{\tt )history )change} {\it n}
\item{\tt )history )memory}
\item{\tt )history )file}
\item{\tt \%}
\item{\tt \%\%({\it n})}
\item{\tt )set history on | off}
\end{list}

\par\noindent{\bf Command Description:}

The {\it history} facility within Axiom allows you to restore your
environment to that of another session and recall previous
computational results.
Additional commands allow you to review previous
input lines and to create an {\bf .input} file of the lines typed to
\index{file!input}
Axiom.

Axiom saves your input and output if the history facility is
turned on (which is the default).
This information is saved if either of
\begin{verbatim}
)set history on
)history )on
\end{verbatim}
has been issued.
Issuing either
\begin{verbatim}
)set history off
)history )off
\end{verbatim}
will discontinue the recording of information.
\index{history )on}
\index{set history on}
\index{set history off}
\index{history )off}

Whether the facility is disabled or not,
the value of {\tt \%} in Axiom always
refers to the result of the last computation.
If you have not yet entered anything,
{\tt \%} evaluates to an object of type
{\tt Variable('\%)}.
The function {\tt \%\%} may be  used to refer
to other previous results if the history facility is enabled.
In that case,
{\tt \%\%(n)} is  the output from step {\tt n} if {\tt n > 0}.
If {\tt n < 0}, the step is computed relative to the current step.
Thus {\tt \%\%(-1)} is also the previous step,
{\tt \%\%(-2)}, is the  step before that, and so on.
If an invalid step number is given, Axiom will signal an error.

The {\it environment} information can either be saved in a file or entirely in
memory (the default).
Each frame 
(\ref{ugSysCmdframe} on page~\pageref{ugSysCmdframe})
has its own history database.
When it is kept in a file, some of it may also be kept in memory for
efficiency.
When the information is saved in a file, the name of the file is
of the form {\bf FRAME.axh} where ``{\bf FRAME}'' is the name of the
current frame.
The history file is placed in the current working directory
(see \ref{ugSysCmdcd} on page~\pageref{ugSysCmdcd}).
Note that these history database files are not text files (in fact,
they are directories themselves), and so are not in human-readable
format.

The options to the {\tt )history} command are as follows:

\begin{description}
\item[{\tt )change} {\it n}]
will set the number of steps that are saved in memory to {\it n}.
This option only has effect when the history data is maintained in a
file.
If you have issued {\tt )history )memory} (or not changed the default)
there is no need to use {\tt )history )change}.
\index{history )change}

\item[{\tt )on}]
will start the recording of information.
If the workspace is not empty, you will be asked to confirm this
request.
If you do so, the workspace will be cleared and history data will begin
being saved.
You can also turn the facility on by issuing {\tt )set history on}.

\item[{\tt )off}]
will stop the recording of information.
The {\tt )history )show} command will not work after issuing this
command.
Note that this command may be issued to save time, as there is some
performance penalty paid for saving the environment data.
You can also turn the facility off by issuing {\tt )set history off}.

\item[{\tt )file}]
indicates that history data should be saved in an external file on disk.

\item[{\tt )memory}]
indicates that all history data should be kept in memory rather than
saved in a file.
Note that if you are computing with very large objects it may not be
practical to kept this data in memory.

\item[{\tt )reset}]
will flush the internal list of the most recent workspace calculations
so that the data structures may be garbage collected by the underlying
Common Lisp system.
Like {\tt )history )change}, this option only has real effect when
history data is being saved in a file.

\item[{\tt )restore} [{\it savedHistoryName}]]
completely clears the environment and restores it to a saved session, if
possible.
The {\tt )save} option below allows you to save a session to a file
with a given name. If you had issued
{\tt )history )save jacobi}
the command
{\tt )history )restore jacobi}
would clear the current workspace and load the contents of the named
saved session. If no saved session name is specified, the system looks
for a file called {\bf last.axh}.

\item[{\tt )save} {\it savedHistoryName}]
is used to save  a snapshot of the environment in a file.
This file is placed in the current working directory
(see \ref{ugSysCmdcd} on page~\pageref{ugSysCmdcd}).
Use {\tt )history )restore} to restore the environment to the state
preserved in the file.
This option also creates an input file containing all the lines of input
since you created the workspace frame (for example, by starting your
Axiom session) or last did a {\tt )clear all} or
{\tt )clear completely}.

\item[{\tt )show} [{\it n}] [{\tt both}]]
can show previous input lines and output results.
{\tt )show} will display up to twenty of the last input lines
(fewer if you haven't typed in twenty lines).
{\tt )show} {\it n} will display up to {\it n} of the last input lines.
{\tt )show both} will display up to five of the last input lines and
output results.
{\tt )show} {\it n} {\tt both} will display up to {\it n} of the last
input lines and output results.

\item[{\tt )write} {\it historyInputFile}]
creates an {\bf .input} file with the input lines typed since the start
of the session/frame or the last {\tt )clear all} or {\tt )clear
completely}.
If {\it historyInputFileName} does not contain a period (``.'') in the filename,
{\bf .input} is appended to it.
For example,
{\tt )history )write chaos}
and
{\tt )history )write chaos.input}
both write the input lines to a file called {\bf chaos.input} in your
current working directory.
If you issued one or more {\tt )undo} commands,
{\tt )history )write}
eliminates all
input lines backtracked over as a result of {\tt )undo}.
You can edit this file and then use {\tt )read} to have Axiom process
the contents.
\end{description}

\par\noindent{\bf Also See:}
{\tt )frame} \index{ugSysCmdframe},
{\tt )read} \index{ugSysCmdread},
{\tt )set} \index{ugSysCmdset}, and
{\tt )undo} \index{ugSysCmdundo}.


History recording is done in two different ways:
\begin{itemize}
\item all changes in variable bindings (i.e. previous values) are
    written to [[$HistList]], which is a circular list
\item all new bindings (including the binding to [[%]]) are written to a
    file called [[histFileName()]]
    one older session is accessible via the file [[$oldHistFileName()]]
\end{itemize}

\section{Variables Used}
The following global variables are used:
\begin{list}{}
\item [[$HistList]], [[$HistListLen]] and [[$HistListAct]] which is the
       actual number of ``undoable'' steps)
\item [[$HistRecord]] collects the input line, all variable bindings
      and the output of a step, before it is written to the file
      [[histFileName()]].
\item [[$HiFiAccess]] is a flag, which is reset by [[)history )off]]
\end{list}
The result of step n can be accessed by [[%n]], which is translated
into a call of [[fetchOutput(n)]]. The 
[[updateHist]] is called after every interpreter step. The 
[[putHist]] function records all changes in the environment to [[$HistList]]
  and [[$HistRecord]]
 
\subsection{Initialized history variables}
\begin{verbatim}
\end{verbatim}
 
<<initvars>>=
(defvar |$historyDirectory| 'A        "vm/370 filename disk component")
(defvar |$HiFiAccess| t               "t means turn on history mechanism")
@

\section{Data Structures}
\section{Functions}

\subsection{defun setHistoryCore}
We [[case]] on the [[inCore]] argument value
\begin{list}{}
\item If history is already on and is kept in the same location as requested
(file or memory) then complain.
\item If history is not in use then start using the file or memory as 
requested. This is done by simply setting the [[$useInternalHistoryTable]] 
to the requested value, where [[T]] means use memory and [[NIL]] means
use a file. We tell the user.
\item If history should be in memory, that is [[inCore]] is not [[NIL]],
and the history file already contains information we read the information
from the file, store it in memory, and erase the history file. We modify
[[$useInternalHistoryTable]] to [[T]] to indicate that we're maintining
the history in memory and tell the user.
\item Otherwise history must be on and in memory. We erase any old history
file and then write the in-memory history to a new file
\end{list}


\section{History File Messages}
<<History File Messages>>=
S2IH0001
 You have not reached step %1b yet, and so its value cannot be
 supplied.
S2IH0002
 Cannot supply value for step %1b because 1 is the first step.
S2IH0003
 Step %1b has no value.
S2IH0004
 The history facility is not on, so you cannot use %b %% %d .
S2IH0006
 You have not used the correct syntax for the %b history %d command.
 Issue %b )help history %d for more information.
S2IH0007
 The history facility is already on.
S2IH0008
 The history facility is now on.
S2IH0009
 Turning on the history facility will clear the contents of the
 workspace.
 Please enter %b y %d or %b yes %d if you really want to do this:
S2IH0010
 The history facility is still off.
S2IH0011
 The history facility is already off.
S2IH0012
 The history facility is now off.
S2IH0013
 The history facility is not on, so the .input file containing your user input
 cannot be created.
S2IH0014
 Edit %b %1 %d to see the saved input lines.
S2IH0015
 The argument %b n %d for %b )history )change n must be a nonnegative
 integer and your argument, %1b , is not one.
S2IH0016
 The history facility is not on, so no information can be saved.
S2IH0018
 The saved history file is %1b .
S2IH0019
 There is no history file, so value of step %1b is
 undefined.
S2IH0022
 No history information had been saved yet.
S2IH0023
 %1b is not a valid filename for the history file.
S2IH0024
 History information cannot be restored from %1b because the file does
 not exist.
S2IH0025
 The workspace has been successfully restored from the history file
 %1b .
S2IH0026
 The history facility command %1b cannot be performed because the
 history facility is not on.
S2IH0027
 A value containing a %1b is being saved in a history file or a
 compiled input file INLIB. This type
 is not yet usable in other history operations.  You might want to issue
 %b )history )off %d
S2IH0029
 History information is already being maintained in an external file
 (and not in memory).
S2IH0030
 History information is already being maintained in memory (and not
 in an external file).
S2IH0031
 When the history facility is active, history information will be
 maintained in a file (and not in an internal table).
S2IH0032
 When the history facility is active, history information will be
 maintained in memory (and not in an external file).
S2IH0034
 Missing element in internal history table.
S2IH0035
 Can't save the value of step number %1b.  You can re-generate this value
 by running the input file %2b.
S2IH0036
 The value specified cannot be saved to a file.
S2IH0037
 You must specify a file name to the history save command
S2IH0038
 You must specify a file name to the history write command
@

\chapter{The Frame Mechanism}
\section{)frame}
%\label{ugSysCmdframe}
%\index{frame}
\par\noindent{\bf Command Syntax:}
\begin{list}{}
\item{\tt )frame  new  {\it frameName}}
\item{\tt )frame  drop  {\it [frameName]}}
\item{\tt )frame  next}
\item{\tt )frame  last}
\item{\tt )frame  names}
\item{\tt )frame  import {\it frameName} {\it [objectName1 [objectName2 ...]]}}
\item{\tt )set message frame on | off}
\item{\tt )set message prompt frame}
\end{list}

\par\noindent{\bf Command Description:}

A {\it frame} can be thought of as a logical session within the
physical session that you get when you start the system.  You can
have as many frames as you want, within the limits of your computer's
storage, paging space, and so on.
Each frame has its own {\it step number}, {\it environment} and {\it history.}
You can have a variable named {\tt a} in one frame and it will
have nothing to do with anything that might be called {\tt a} in
any other frame.

Some frames are created by the HyperDoc program and these can
have pretty strange names, since they are generated automatically.
\index{frame names}
To find out the names
of all frames, issue
\begin{verbatim}
)frame names
\end{verbatim}
It will indicate the name of the current frame.

You create a new frame
\index{frame new}
``{\bf quark}'' by issuing
\begin{verbatim}
)frame new quark
\end{verbatim}
The history facility can be turned on by issuing either
{\tt )set history on} or {\tt )history )on}.
If the history facility is on and you are saving history information
in a file rather than in the Axiom environment
then a history file with filename {\bf quark.axh} will
be created as you enter commands.
If you wish to go back to what
you were doing in the
\index{frame next}
``{\bf initial}'' frame, use
\index{frame last}
\begin{verbatim}
)frame next
\end{verbatim}
or
\begin{verbatim}
)frame last
\end{verbatim}
to cycle through the ring of available frames to get back to
``{\bf initial}''.

If you want to throw
away a frame (say ``{\bf quark}''), issue
\begin{verbatim}
)frame drop quark
\end{verbatim}
If you omit the name, the current frame is dropped.
\index{frame drop}

If you do use frames with the history facility on and writing to a file,
you may want to delete some of the older history files.
\index{file!history}
These are directories, so you may want to issue a command like
{\tt rm -r quark.axh} to the operating system.

You can bring things from another frame by using
\index{frame import}
{\tt )frame import}.
For example, to bring the {\tt f} and {\tt g} from the frame ``{\bf quark}''
to the current frame, issue
\begin{verbatim}
)frame import quark f g
\end{verbatim}
If you want everything from the frame ``{\bf quark}'', issue
\begin{verbatim}
)frame import quark
\end{verbatim}
You will be asked to verify that you really want everything.

There are two {\tt )set} flags
\index{set message frame}
to make it easier to tell where you are.
\begin{verbatim}
)set message frame on | off
\end{verbatim}
will print more messages about frames when it is set on.
By default, it is off.
\begin{verbatim}
)set message prompt frame
\end{verbatim}
will give a prompt
\index{set message prompt frame}
that looks like
\begin{verbatim}
initial (1) ->
\end{verbatim}
\index{prompt!with frame name}
when you start up. In this case, the frame name and step make up the
prompt.

\par\noindent{\bf Also See:}
{\tt )history} \index{ugSysCmdhistory} and
{\tt )set} \index{ugSysCmdset}.


@
\section{Variables Used}
\section{Data Structures}
\section{Functions}


\section{Frame File Messages}
<<Frame File Messages>>=
S2IZ0016
 The %1b system command takes arguments but no options.
S2IZ0017
 %1b is not a valid frame name
S2IZ0018
 You must provide a name for the new frame.
S2IZ0019
 You cannot use the name %1b for a new frame because an existing
 frame already has that name.
S2IZ0020
 There is only one frame active and therefore that cannot be closed.
 Furthermore, the frame name you gave is not the name of the current frame.
 The current frame is called %1b .
S2IZ0021
 The current frame is the only active one.  Issue %b )clear all %d to
 clear its contents.
S2IZ0022
 There is no frame called %1b and so your command cannot be
 processed.
S2IZ0024
 The names of the existing frames are: %1 %l
 The current frame is the first one listed.
S2IZ0073
 %b )frame import %d must be followed by the frame name. The names
 of objects in that frame can then optionally follow the frame name.
 For example,
 %ceon %b )frame import calculus %d %ceoff
 imports all objects in the %b calculus %d frame, and
 %ceon %b )frame import calculus epsilon delta %d %ceoff
 imports the objects named %b epsilon %d and %b delta %d from the
 frame %b calculus %d .
 Please note that if the current frame contained any information
 about objects with these names, then that information would be
 cleared before the import took place.
S2IZ0074
 You cannot import anything from the frame %1b because that is not
 the name of an existing frame.
S2IZ0075
 You cannot import from the current frame (nor is there a need!).
S2IZ0076
 User verification required:
 do you really want to import everything from the frame %1b ?
 If so, please enter %b y %d or %b yes %d :
S2IZ0077
 On your request, OpenAxiom will not import everything from frame %1b.
S2IZ0078
 Import from frame %1b is complete. Please issue %b )display all %d
 if you wish to see the contents of the current frame.
S2IZ0079
 OpenAxiom cannot import %1b from frame %2b because it cannot be found.
@
\chapter{The Undo Mechanism}
\section{)undo}
\index{ugSysCmdundo}

\index{undo}


\par\noindent{\bf User Level Required:} interpreter

\par\noindent{\bf Command Syntax:}
\begin{list}{}
\item{\tt )undo}
\item{\tt )undo} {\it integer}
\item{\tt )undo} {\it integer [option]}
\item{\tt )undo} {\tt )redo}
\end{list}
%
where {\it option} is one of
%
\begin{list}{}
\item{\tt )after}
\item{\tt )before}
\end{list}

\par\noindent{\bf Command Description:}

This command is used to
restore the state of the user environment to an earlier
point in the interactive session.
The argument of an {\tt )undo} is an integer which must designate some
step number in the interactive session.

\begin{verbatim}
)undo n
)undo n )after
\end{verbatim}
These commands return the state of the interactive
environment to that immediately after step {\tt n}.
If {\tt n} is a positive number, then {\tt n} refers to step nummber
{\tt n}. If {\tt n} is a negative number, it refers to the \tt n-th
previous command (that is, undoes the effects of the last $-n$
commands).

A {\tt )clear all} resets the {\tt )undo} facility.
Otherwise, an {\tt )undo} undoes the effect of {\tt )clear} with
options {\tt properties}, {\tt value}, and {\tt mode}, and
that of a previous {\tt undo}.
If any such system commands are given between steps $n$ and
$n + 1$ ($n > 0$), their effect is undone
for {\tt )undo m} for any $0 < m \leq n$..

The command {\tt )undo} is equivalent to {\tt )undo -1} (it undoes
the effect of the previous user expression).
The command {\tt )undo 0} undoes any of the above system commands
issued since the last user expression.

\begin{verbatim}
)undo n )before
\end{verbatim}
This command returns the state of the interactive
environment to that immediately before step {\tt n}.
Any {\tt )undo} or {\tt )clear} system commands
given before step {\tt n} will not be undone.

\begin{verbatim}
)undo )redo
\end{verbatim}
This command reads the file {\tt redo.input}.
created by the last {\tt )undo} command.
This file consists of all user input lines, excluding those
backtracked over due to a previous {\tt )undo}.

\par\noindent{\bf Also See:}
{\tt )history} \index{ugSysCmdhistory}.
The command {\tt )history )write} will eliminate the ``undone'' command
lines of your program.
\section{Variables Used}
\section{Data Structures}
[[$frameRecord = [delta1, delta2,... ] ]] where
[[delta(i)]] contains changes in the ``backwards'' direction.
Each [[delta(i)]] has the form [[((var . proplist)...)]] where
proplist denotes an ordinary proplist. For example, an entry
of the form [[((x (value) (mode (Integer)))...)]] indicates that
to undo 1 step, [[x]]'s value is cleared and its mode should be set
to [[(Integer)]].

A [[delta(i)]] of the form [[(systemCommand . delta)]] is a special
delta indicating changes due to system commands executed between
the last command and the current command. By recording these deltas
separately, it is possible to undo to either BEFORE or AFTER
the command. These special [[delta(i)]]s are given ONLY when a
a system command is given which alters the environment.

Note: [[recordFrame('system)]] is called before a command is executed, and
[[recordFrame('normal)]] is called after (see processInteractive1).
If no changes are found for former, no special entry is given.

The [[$previousBindings]] is a copy of the 
[[CAAR $InteractiveFrame]]. This is used to
compute the [[delta(i)]]s stored in [[$frameRecord]].
\section{Functions}
\subsection{Initial Undo Variables}
\begin{verbatim}
\end{verbatim}
<<initvars>>=
(defvar |$reportUndo| nil "t means we report the steps undo takes")
@


\subsection{defun reportUndo}
This function is enabled by setting [[|$reportUndo]] to a non-nil value.
An example of the output generated is:
\begin{verbatim}
r := binary(22/7)
 

           ___
   (1)  11.001
                                                        Type: BinaryExpansion
Properties of % ::
  value was: NIL
  value is:  ((|BinaryExpansion|) WRAPPED . #(1 (1 1) NIL (0 0 1)))
Properties of r ::
  value was: NIL
  value is:  ((|BinaryExpansion|) WRAPPED . #(1 (1 1) NIL (0 0 1)))

\end{verbatim}


\chapter{The Spad Server Mechanism}
<<initvars>>=
(defvar $openServerIfTrue t "t means try starting an open server")
(defconstant $SpadServerName "/tmp/.d" "the name of the spad server socket")
(defvar |$SpadServer| nil "t means Scratchpad acts as a remote server")

@

\chapter{Axiom Build-time Functions}
\subsection{defun spad-save}
The {\bf spad-save} function is just a cover function for more
lisp system specific save functions. There is no standard name
for saving a lisp image so we make one and conditionalize it
at compile time.

This function is passed the name of an image that will be saved.
The saved image contains all of the loaded functions.

This is used in the [[src/interp/Makefile.pamphlet]] in three places:
\begin{list}{}
\item creating depsys, an image for compiling axiom.

Some of the Common Lisp code we compile uses macros which
are assumed to be available at compile time. The {\bf DEPSYS}
image is created to contain the compile time environment
and saved. We pipe compile commands into this environment
to compile from Common Lisp to machine dependent code.
\begin{verbatim}
DEPSYS=	${OBJ}/${SYS}/bin/depsys
\end{verbatim}

\item creating savesys, an image for running axiom.

Once we've compile all of the Common Lisp files we fire up
a clean lisp image called {\bf LOADSYS}, load all of the
final executable code and save it out as {\bf SAVESYS}.
The {\bf SAVESYS} image is copied to the [[${MNT}/${SYS}/bin]]
subdirectory and becomes the axiom executable image.
\begin{verbatim}
LOADSYS= ${OBJ}/${SYS}/bin/lisp
SAVESYS= ${OBJ}/${SYS}/bin/interpsys
AXIOMSYS= ${MNT}/${SYS}/bin/AXIOMsys
\end{verbatim}


\item creating debugsys, an image with all interpreted functions loaded.

Occasionally we need to really get into the system internals.
The best way to do this is to run almost all of the lisp code
interpreted rather than compiled (note that cfuns.lisp and sockio.lisp
still need to be loaded in compiled form as they depend on the 
loader to link with lisp internals). This image is nothing more
than a load of the file src/interp/debugsys.lisp.pamphlet. If
you need to make test modifications you can add code to that
file and it will show up here.
\begin{verbatim}
DEBUGSYS=${OBJ}/${SYS}/bin/debugsys
\end{verbatim}
\end{list}
<<defun spad-save>>=
(defun spad-save (save-file)
  (setq |$SpadServer| nil)
  (setq $openServerIfTrue t)
#+:AKCL
  (system::save-system save-file)
#+:allegro
  (if (fboundp 'boot::restart)
   (excl::dumplisp :name save-file :restart-function #'boot::restart)
   (excl::dumplisp :name save-file))
#+Lucid
  (if (fboundp 'boot::restart)
   (sys::disksave save-file :restart-function #'boot::restart)
   (sys::disksave save-file))
#+:CCL
  (preserve)
)

@

\chapter{The Interpreter}
<<Interpreter>>=
(IMPORT-MODULE "vmlisp")
(in-package "BOOT")
<<initvars>>

<<defun init-memory-config>>
<<defun initroot>>

<<defun loadExposureGroupData>>

<<defun make-absolute-filename>>

<<defun reclaim>>

<<defun reroot>>
<<defun restart>>

<<defun set-restart-hook>>
<<defun spad-save>>
<<defun statisticsInitialization>>

@
\chapter{Makefile.bookvol5}
<<*>>=

all: bookvol5
	@echo 0 done

bookvol5: bookvol5.pamphlet
	${TANGLE} -R"Interpreter" bookvol5.pamphlet >bookvol5.lisp

remake:	
	@echo 2 rebuilding the makefile
	@${TANGLE} bookvol5.pamphlet >Makefile.bookvol5

@
\eject
\begin{thebibliography}{99}
\bibitem nothing
\end{thebibliography}
\end{document}