% from 20.3.1989 hk, version 0.03
% revised 5.11.1989 hk, version 0.30
% corrections by haible 25.9.90

% rest pragmas, lisp, m2, etc.

\chapter{System Commands} %-------------------------

In this chapter we summarize display commands, pragmas, 
how to access the operating system and command line parameters. 

\section{Information Display} %----------

The first important system commands are concerned with 
displaying information on the system configuration and 
what is going on during computations.
There are three groups of commands: 
1) for configuration display,
2) for specification display and 
3) for environment display.

Configuration display commands show which 
external functions or predefined functions are available. 
Specification display commands show 
defined units, sorts, variables, signatures and generic items.
Environment display commands show 
storage usage, stream usage, symbol table contents, 
and top level variable bindings.
A summary of this commands follows:

\begin{deflist}{GENERICS}
\item[help\index{help}] and 
\item[HELP\index{HELP}] lists all information available on 
      defined and accessible functions.
      That is all compiled procedures and functions,
      all interpreter procedures and functions
      and all signature\index{signature! definition} definitions.
      The syntax is 
      \begin{verbatim}
   help(name[,mod])   or   help(start,end[,mod])
      \end{verbatim}
      '\verb/Name/' means the first characters of a range of names,
      '\verb/start,end/' means a range of names and 
      '\verb/all/' means all names (this implies \verb/Loaded/). 
      '\verb/,mod/' is optional and '\verb/mod/' can be 
      '\verb/ModulName/' to list module names of the procedures,
      '\verb/Loaded/' to list loaded procedures, 
      '\verb/Comment/' to list procedure comments 
      (this is the default except for \verb/all/).
\item[EXTPROCS\index{EXTPROCS}] lists all accessible external 
      compiled functions and procedures.
\item[SIGS\index{SIGS}] lists all 
      signature definitions\index{signature! definition} 
      of functions.
\item[GENERICS\index{GENERICS}] lists all generic\index{generic} 
      function definitions.
\item[VARS\index{VARS}] lists all defined variables\index{variable}
      together with the type information. 
\item[SORTS\index{SORTS}] lists all defined 
      sorts names\index{sort! name}. 
\item[UNITS\index{UNITS}] lists all defined 
      unit names\index{unit! name}. 

\item[BIOS\index{BIOS}] displays information on stream I/O usage, 
\item[GCM\index{GCM}] displays information on the 
      storage\index{storage} usage, 
\item[SYMTB\index{SYMTB}] displays the LISP symbol\index{symbol} 
      table including properties, 
\item[DUMPENV\index{DUMPENV}] lists all variable bindings, 
      that is all variables\index{variable} in the top level 
      environment together
      with their current value. The output is in LISP syntax:
\begin{verbatim}
       (SETQ var value)
\end{verbatim}
      so it should be possible to dump the variables to a disk
      file, and later read them in again.
      Declarations are lost.
\item[LISTENV\index{LISTENV}] same as DUMPENV except output is in 
      Modula--2 like syntax. 
      Note that probably some constructs can not be read in again.
\item[PRAGMA(SHOW)\index{PRAGMA}\index{SHOW}] 
      displays the actual pragma settings.
\end{deflist}

Note that all display information can be 
printed to a file using output stream setting. 


\section{Pragmas} %---------

\label{prag.sec}
Besides displaying information the MAS system provides 
commands to modify the state of the running MAS program. 
These settings are organized by the \verb/PRAGMA/ command. 
The pragmas come in two groups, 
one for the selection of the actual parser and 
one for debugging purposes. 
\index{PRAGMA}

The general syntax of the pragma command is as follows:
\begin{verbatim}
       PRAGMA(subcommand).
\end{verbatim}
Where \verb/subcommand/ is one of the commands discussed in
the sequel. If an unknown subcommand is entered, then 
a list of all available pragmas is displayed. 
A list of the actual pragma settings is available with the 
\verb/SHOW/ subcommand.

The subcommands which modify and select the parser 
are as follows:

\begin{deflist}{MODULA}
\item[MODULA\index{MODULA}] input / output is in Modula--2 like 
      syntax\index{syntax}, 
      that means the MAS parser for the MAS language is used. 
\item[LISP\index{LISP}] input / output is in LISP syntax. 
\item[ALDES\index{ALDES}] input is in ALDES--2 syntax, 
      that means the ALDES parser is used to read 
      the next input until the ALDES end of file mark `\verb/||/'
      is encountered.
\item[GENPARSE\index{GENPARSE}] for the artihmetical operators 
      the generic names or LISP names are generated. The 
      correspondence is as shown in table \ref{gen.fig}.
\end{deflist}
\begin{table}[thbp] %-----------------------------
\begin{center}
\begin{tabular}{|c|l|l|} 
      \hline
      operator &  LISP name  & generic name \\
      \hline
      \verb/+/ &  \verb/ADD/  & \verb/SUM/ \\
      \verb/-/ &  \verb/SUB/  & \verb/DIF/ \\
      \verb/-/ &  \verb/SUB/  & \verb/NEG/ \\
      \verb/*/ &  \verb/MUL/  & \verb/PROD/ \\
      \verb./. &  \verb/QUOT/ & \verb/Q/ \\
      \verb.%. &  \verb/REM/  & \verb/REMAIN/ \\
               &              & \verb/REZIP/ \\
      \verb.^. &  \verb/POW/  & \verb/EXP/ \\
      \hline
\end{tabular}
\end{center}
\caption{Generic Operators and Functions}
\label{gen.fig}\index{generic! operators}\index{operator! overloading}
\end{table} %---------------------------

The following subcommands turn {\bf flags} ON and OFF:

\begin{deflist}{SLOPPY}
\item[TIME\index{TIME}] if ON the times for 
     parsing, evaluation and printing are shown 
     (initial OFF), 
\item[TRACE\index{TRACE}] if ON the arguments of the evaluator 
      are displayed, may produce messy output 
     (initial OFF),
\item[DEBUG\index{DEBUG}] if ON prints the result produced 
      by the actual parser\index{parser} 
     (initial OFF)
\item[FUSSY\index{FUSSY}] switches to strong(er) 
      type checking as usual.
\item[SLOPPY\index{SLOPPY}] switches to weak(er) 
      type checking.
\end{deflist}

The actual setting of these flags can be displayed with the 
\verb/SHOW/ subcommand. 


\section{Operating System}

With \verb/EXIT/ it is possible to leave the MAS main program 
and return to the operating system.
On some computers the MAS system further provides
access to the operating system during a running MAS session. 
Most important is the possibility to call an editor
from within MAS. 
The commands are summarized as follows:
\begin{deflist}{EDIT()}
\item[EXIT\index{EXIT}] Leaves the MAS system. 
\item[DOS(\verb*/"prog parms"/)\index{DOS}]  calls the program 
      `\verb/prog/' with the parameters `\verb/parms/'. 
      The meaning of the string depends on the operating system.
\item[EDIT(\verb*/"data set name"/)\index{EDIT}] edits 
      the specified data set. 
      The editor\index{editor} is expected to be 
      `EDITOR.PRG' on the current directory\index{directory}. 
      The editor on disk is `microEMACS 3.9'. 
      The data set name string is prefixed by the
      string \verb*/" @MAS.RC "/ which specifies the startup file
      for EMACS to be `MAS.RC'.
      \index{EMACS}\index{MAS.RC}
%\item[USEEMS\index{USEEMS}] Activates the usage of the EMS storage 
%      on IBM PC's if available. 
%      \index{IBM! PC}\index{EMS}
\end{deflist}


\section{Input / Output}

The MAS input / output is organized in so called streams. 
A discussion of streams and their usage is contained 
in the chapter on the MAS language \ref{lang.chap}.
In this section we give only a summary of the functions.

The stream switching functions are:
\begin{deflist}{SHUT()}
\item[IN(\verb/"stream"/)\index{IN}] the current input stream 
      is switched to the stream `stream',
\item[OUT(\verb/"stream"/)\index{OUT}] the current output stream 
      is switched to the stream `stream',
\item[SHUT(\verb/"stream"/)\index{SHUT}] the specified stream 
      is closed. 
\end{deflist}

The `stream' name may be prefixed by a `device name' to specify
non--disk data sets:
\begin{description}
\item[CON:] is the terminal
\item[WIN:] is a window (not yet implemented)
\item[RAM:] is an internal memory stream, 
            `RAM--disk'
\item[GRA:] is a graphic\index{graphic} window (not yet implemented)
\item[NUL:] is a dummy stream to suppress output\index{output}, 
            always empty on input, never full on output,
\end{description}
\index{WIN}\index{CON}\index{RAM}\index{GRA}\index{NUL}

Other `device names' are passed to the 
operating system\index{operating system} and
are usually interpreted as disk data sets.


\section{Command Line Parameters}

The executable MAS program accepts several 
command line parameters to configure the 
running system. 
\index{command! line}

The MAS command line syntax is as follows:
\begin{verbatim}
       mas [Options] [File]  
\end{verbatim}
where \verb/[File]/ is a file with MAS input (the default extension
is \verb/.mas/
and \verb/[Options]/ are some of the following options. 

\begin{enumerate}
\item \verb/--help/ \\
      Display a list of available command line parameters and exit.
      \index{\verb/--help/}
\item \verb/--version/ \\
      Output version information and exit.
      \index{\verb/--version/}
\item \verb/-C/ or \verb/--copyright/ \\
      Displays copyright and copying conditions.
      \index{\verb/-C/}\index{\verb/--copyright/}
\item \verb/-c COMMAND/ or \verb/--command=COMMAND/ \\
      Execute MAS command \verb/COMMAND/ before reading File..
      \index{\verb/-c COMMAND/}\index{\verb/--command=COMMAND/}
\item \verb/-e/ or \verb/--exit/ \\
      Exit after all input files have been read and processed.
      \index{\verb/-e/}\index{\verb/--exit/}
\item \verb/-E/ or \verb/--exit-on-error/ \\
      Exit when an error occurs. 
      \index{\verb/-E/}\index{\verb/--exit-on-error/}
\item \verb/-f FILE/ or \verb/--file=FILE/ \\
      Process input initialization file \verb/FILE/ instead of default. 
      The file name option `\verb/-f/' can be used to overwrite the
      default file name `~/.masrc' during startup.
      \index{\verb/-f FILE/}\index{.masrc}
      \index{\verb/--file=FILE/}
\item \verb/-m SIZE/ or \verb/--memorysize=SIZE/ \\
      Set size of MAS memory to SIZE kbytes.
      The memory option `\verb/-m/' gives the number of Kilobyte
      storage, requested from the operating system.
%      This
%      number includes the space reserved for the editor and
%      other system calls. 
%      The number should be larger than
%      about 250-300 on an Atari ST with microEMACS.
      \index{\verb/-m SIZE/}\index{\verb/--memorysize=SIZE/}
\item \verb/-o[FILE]/ or \verb/--output[=FILE]/ \\
      Write output to file (named \verb/FILE/ or some default name).  
      \index{\verb/-o[FILE]/}\index{\verb/--output[=FILE]/}
\item \verb/-R/ or \verb/--no-readline/ \\
      Do not use the GNU readline library for interactive input.
      \index{\verb/-R/}\index{\verb/--no-readline/}
\end{enumerate}
The parameters may appear in any order.
On multiple occurrences of parameters, the last
occurrence is used.

%An additional parameter available on IBM PC Topspeed Modula--2
%version is: 
%\begin{enumerate}
%\item \verb/-t data-set-name/ \\
%      This parameter defines an temporary data set name 
%      used for storing MAS memory during external command 
%      invocation. The default for data-set-name is 
%      `CELLMEM.TMP'. i.e the temporary data set is created in 
%      the actual directory. If you have a RAM-Disk installed, 
%      say on drive `R', then with `\verb/MAS -t R:\temp.tmp/'
%      MAS will use the RAM-Disk for the temorary data set.
%      \index{\verb/-t/}
%\end{enumerate}
%For the IBM PC version at least 512 KB memory is required,
%but it is recommended to have at least 640 KB.
%In case of problems starting MAS you should remove any
%additional device drivers from CONFIG.SYS and AUTOEXEC.BAT
%or any other program that needs memory.
%\index{IBM! PC}\index{RAM-disk}
%The MAS version compiled with the Topspeed Modula-2 Compiler
%uses EMS if present. Memory from EMS will be activated 
%after 10 Garbage Collections or by the MAS function USEEMS(). 
%\index{EMS}


\section{The LISP Interpreter} %--------------------------------

This section describes some issues of the LISP interpreter
which are not covered elsewhere. It is usually not required 
for the use of the MAS system. LISP whizzards may find some
background information regarding the MAS LISP implementation.
In the chapter on the internal structure of MAS there is also a section 
on implementation dependent issues.

\subsection{Functions and Variables}

Since in LISP everything is a function and there is no 
special syntax beyond the S--expression syntax we 
describe the MAS LISP by the functions.
The semantics of the functions is as expected from other LISP systems.
The list of all available 
LISP\index{LISP} functions is as follows: 

\begin{description}
\item[List Processing:] \mbox{ }
      \\
      CAR\index{CAR}, CDR\index{CDR}, CONS\index{CONS}, 
      REVERSE\index{REVERSE}, JOIN\index{JOIN}, NIL\index{NIL} 
      (LISP\index{LISP} like versions)
      \\
      FIRST\index{FIRST}, RED\index{RED}, COMP\index{COMP}, 
      INV\index{INV}, CONC\index{CONC}, ADV\index{ADV} 
      (SAC--2 like versions).
\end{description}

For convenience both the LISP names and the ALDES /SAC--2 names
are available. The names are in corresponding order. 
NIL is the empty list. The ALDES constant `()' is not parsed, so
NIL must be used. 

The next functions correspond to the operators 
\verb. +, -, *, /, %. in the MAS language\index{language}.

\begin{description}
\item[Arithmetic:] \mbox{ }
      \\
      ADD\index{ADD}, SUB\index{SUB}, MUL\index{MUL}, 
      QUOT\index{QUOT}, REM\index{REM}.
\end{description}

\begin{description}
\item[Relations:] \mbox{ }
     \\
     EQ\index{EQ}, NE\index{NE}, LE, LT\index{LT}, GE, GT, 
     NOT\index{NOT}, AND\index{AND}, OR\index{OR}.
\end{description}

These functions are generated from the MAS relations
\verb. =, #, <=, <, >=, >..

The following is a complete list of the intrinsic LISP
functions. The functions with Standard LISP names 
have the same meaning as in SLISP. Others are described 
elsewhere.

\begin{description}
\item[Functions:] \mbox{ }
     \\
     DE\index{DE}, DF\index{DF}, DM, DG\index{DG}, 
     LAMBDA\index{LAMBDA}, FLAMBDA\index{FLAMBDA}, 
     MLAMBDA\index{MLAMBDA}, GLAMBDA\index{GLAMBDA}, 
     \\
     VAR\index{VAR}, SORT\index{SORT}, 
     SIG\index{SIG}, MAP\index{MAP}, RULE\index{RULE},
     \\
     UNIT\index{UNIT}, SPEC\index{SPEC}, IMPL\index{IMPL}, 
     MODEL\index{MODEL}, AXIOMS\index{AXIOMS}, 
     \\
     SETQ\index{SETQ}, ASSIGN\index{ASSIGN}, 
     QUOTE\index{QUOTE}, COND\index{COND}, 
     \\
     PROGN\index{PROGN}, LIST\index{LIST}, 
     IF\index{IF}, WHILE\index{WHILE}, REPEAT\index{REPEAT}, 
     \\
     PROGA\index{PROGA}, GOTO\index{GOTO},
     ARRAY\index{ARRAY}, LABEL\index{LABEL},
\end{description}

The VAR, SIG, MAP, RULE, UNIT, SPEC, IMPL, MODEL and AXIOMS
functions are used by the specification component.
The PROGA, GOTO, LABEL and ARRAY functions are used for the 
interpretation of ALDES algorithms.


\subsection{What is Not Contained}

Several functions which are normally available from 
LISP interpreters are not accessible in MAS LISP, but they are 
normally available (probably with different name) 
at the Modula--2 programming level:

\begin{quote}
CATCH\index{CATCH}, THROW\index{THROW}, 
ASSOC\index{ASSOC}, PUT\index{PUT}, GET\index{GET}, 
EXPLODE\index{EXPLODE}, IMPLODE\index{IMPLODE}, 
GENSYM\index{GENSYM}, SUBLIS\index{SUBLIS}.
\end{quote}

Definitely not available are:

\begin{quote}
DO--loops or FOR--loops, a LISP compiler\index{compiler}. 
\end{quote}
Of course a FOR--loop construct can be defined as macro\index{macro}, 
if one accepts an ugly syntax.
GOTO\index{GOTO} is only available 
in PROGA for ALDES sequential statements.

Probably available in future releases will be:
\begin{quote}
LOOP\index{LOOP}--EXIT\index{EXIT}--END, 
CASE\index{CASE}, graphics\index{graphic}, \ldots 
\end{quote}
A CASE construct is available in ALDES, it is simulated using 
the COND function.

Not contained as primitive but definable are 
\begin{quote}
APPLY\index{APPLY}, MAP\index{MAP}, EVAL\index{EVAL}.
\end{quote}
Here MAP means the LISP MAP function family and not the 
specification component MAP function. 
The MAP\index{MAP} function family can be defined as 
procedures, as explained in the section `Talking LISP'.
\index{mapcar}



\chapter{Internal Structure of MAS} %---------------------------

In this chapter we will provide some background 
on the internal structure of MAS. 
First we discuss the components of MAS, then 
the program layout, the configuration and available 
libraries.


\section{System Components}

\begin{table}[thbp] %-----------------------------
\begin{center}
\setlength{\unitlength}{1mm}
\begin{picture}(120,100)
\put(75.3,33){\framebox(33,34.7){}}
\put(19.3,81){\oval(26,9.3)}
\put(42,77){\framebox(25.7,11.3){}}
\put(45,80.7){\makebox(18.3,4)[b]{Editor}}
\put(7.3,79){\makebox(22,5.7)[b]{MAS input}}
\put(77,45.3){\makebox(25,8.7)[b]{compiler}}
\thicklines
\put(90,67.7){\line(0,1){11}}
\put(75,82.7){\line(-1,0){7}}
\put(41.7,82.3){\line(-1,0){9.3}}
\put(75.3,40.3){\vector(-1,0){20.3}}
\put(30.7,26.7){\vector(1,0){44.7}}
\thinlines
\put(8,56.7){\framebox(22.7,8.3){}}
\put(8,45.7){\framebox(22.7,8.3){}}
\put(5,12){\framebox(49.7,58){}}
\put(8,34.7){\framebox(22.7,8.3){}}
\put(8,13.7){\framebox(22.7,8.3){}}
\put(7.7,24.3){\framebox(22.7,8.3){}}
\put(9.3,58.3){\makebox(19,5){Parse}}
\put(10.3,35.7){\makebox(18,5.7){Lisp}}
\put(10,25.7){\makebox(18.3,5.3){Call}}
\put(10.7,15.3){\makebox(17.3,4.7){Print}}
\put(37.3,49){\makebox(11.7,5){Decla-}}
\put(35.3,43.3){\makebox(15.7,5){rations}}
\put(21,5.7){\oval(34,8)}
\put(6.7,3){\makebox(29,5.3){MAS output}}
\thicklines
\put(30.7,52.3){\vector(1,0){4}}
\put(34.3,47){\vector(-1,0){4}}
\put(14.3,76){\vector(0,-1){11.3}}
\put(13.3,13.7){\vector(0,-1){4.7}}
\thinlines
\put(13,48){\vector(0,-1){7}}
\put(12.7,26){\vector(0,-1){5.7}}
\put(49.7,56.3){\line(3,2){33.7}}
\put(42,42){\line(5,-2){34.3}}
\put(35.7,13.3){\makebox(17,7){MAS}}
\put(91.3,21.7){\oval(32.7,17.3)}
\put(91.7,83){\oval(33.3,9.3)}
\put(44,49.3){\oval(18.7,14)}
\thicklines
\put(90,33){\line(0,-1){2.7}}
\put(9.3,47.3){\makebox(20.3,4.7){Specification}}
\put(77,51.3){\makebox(25.7,6.7){Modula--2}}
\put(77.3,17.7){\makebox(28.7,8.3){M--2 libraries}}
\put(76,80){\makebox(31.3,6.3){M--2 source}}
\thinlines
\put(12.7,58.3){\vector(0,-1){7.7}}
\put(12.7,37.7){\vector(0,-1){8.3}}
\end{picture}
\end{center}
\caption{System Components}
\label{figSCo}\index{system! components}
\end{table} %---------------------------

The MAS system components are identified in 
table \ref{figSCo}.
Active components (programs) are enclosed in square boxes
and passive components (data) are enclosed in oval boxes. 
Arrows indicate flow of data and lines between 
boxes show that the components are related in some way.

As already mentioned MAS itself is a 
Modula--2 program. Thus the MAS program can be recompiled 
and linked together with other symbolic and 
numerical libraries by a suitable Modula--2 compiler.
This is shown as an arrow from the compiler box on the right 
to the enclosing MAS box on the left.

On the top line the editor box both acts on the 
Modula--2 source code (on the right) 
and the MAS input data (on the left). 
The input is processed by the following internal components: 
\begin{enumerate}
\item The parser for the MAS language (Parse box):
      character strings in concrete syntax are transformed 
      into abstract syntax trees. Static syntax check together 
      with variable scope analysis is performed.
\item The specification processor (Specification box) 
      with an attached data base of declarations 
      (Declarations box): 
      declarations are extracted from the parse tree and 
      stored in the declaration base, 
      information is retrieved during interpretation.
      The declarations reflect the Modula--2 source code 
      and the library structure.
\item The LISP interpreter (LISP box): 
      according to the type or the function name of an
      S--expression inner most (that is eager) evaluation 
      is performed. 
\item The interface to the compiled library procedures (Call box): 
      if external functions are encountered 
      then compiled procedures are restored and 
      called with the appropriate parameters. 
\item Finally the results are displayed by the 
      (pretty) printing part (Print box).
\end{enumerate}


\section{Module Layout of MAS} %--------------------------------

In this section we will discuss the
internal structure of MAS as a Modula-2 program.
The principal module structure is shown in table \ref{figMSt}.

\begin{table}[thbp] %-----------------------------
\begin{center}
       \framebox[6cm]{Interpreter} \\ 
       \framebox[6cm]{MAS Language} \\ 
       \framebox[6cm]{LISP Evaluator} \\ 
       \framebox[12.3cm]{Modula-2 Subroutine Libraries} \\ 
       \framebox[4cm]{SAC--2 Libraries} 
       \framebox[4cm]{MAS Libraries}
       \framebox[4cm]{Others} \\ 
       \framebox[4cm]{Integer} 
       \framebox[4cm]{Floating Point} 
        \makebox[4cm]{ } \\ 
       \framebox[4cm]{Rational Number} 
       \framebox[4cm]{Others} 
        \makebox[4cm]{ } \\ 
       \framebox[4cm]{Others} 
        \makebox[4cm]{ }
        \makebox[4cm]{ } \\ 
       \framebox[10.1cm]{MAS Kernel} 
        \makebox[2.1cm]{ } \\ 
\end{center}
\caption{Module Structure}
\label{figMSt}\index{module! structure}
\end{table} %---------------------------

The MAS interpreter main program uses the parser module
`MAS Language' and the LISP evaluator module. 
Various library modules can then be connected to 
the LISP interpreter.
All list processing modules use the MAS kernel 
with its storage management system and basic input/output system.

MAS is an open system. Beside the ALDES /SAC--2 and the MAS
libraries other libraries can be connected to the interpreter.
In a first test we used a numerical\index{numeric} 
library\index{library} developed
at the Technische Hochschule Aachen by \cite{Engeln88}. 
It was not only possible to call numerical
programs from MAS, but moreover it was also possible to call
MAS routines from the numerical programs. 

In a differential equation solver we called the 
LISP evaluator from within the function which computes the 
right hand side of the differential equation. 
This might not be the fastest way to do it but it was possible to 
define different right hand sides interactively\index{interactive} 
as MAS procedures and then integrate them numerically. 

The design\index{design} of the 
garbage collector allows arbitrary 
mixtures of list  processing programs with 
numerical\index{numeric} or other
programs. It also allows mixtures with other Modula--2 
data types\index{data type} 
such as real numbers, vectors, arrays or records. 
However it only collects garbage produced by the MAS list processing
system, not any other dynamically allocated data 
structures\index{structure}.
The collector uses a mark and sweep technique and 
is not compacting despite of the open system design\index{design}.

{\bf Restriction:} 
{\em MAS list pointers may not be part of other 
{\bf dynamically allocated} data structures, 
since then the garbage collector 
can not get information about them.} 

This restriction can be overcome in the following way:
Dynamically allocated data structures must be linked together
in some way, so use the MAS list processing for the links and
put pointers to the dynamically allocated data in the FIRST fields 
of the MAS lists. 
If no list pointers are stored in other dynamically allocated
data structures, then no restrictions exist.


\subsection{Program Dependencies} %--------------

A simplified list of the dependencies\index{dependencies} 
of the program modules is contained in the following list. 
Modules with smaller numbers depend on those with higher numbers.
 
\begin{enumerate}
\item MAS.MOD \\
      main program.
\item SACSYM, MASSPEC, MASLISP, MASPARSE, MASLOAD, \\
      (.DEF and .MOD), \\
      symbol\index{symbol} system, interpreter and parser\index{parser}.
\item SACD, SACI, SACM, SACRN, SACPRIM, MASAPF, \\ 
      MASF (.DEF and .MOD), \\
      arithmetic\index{arithmetic} system, or various other 
      programs which are connected 
      to the interpreter.
\item SACBIOS\index{BIOS}, SACLIST (.DEF and .MOD), \\
      rest of ALDES /SAC-2 basic system.
\item MASELEM, MASSTOR, MASBIOS (.DEF and .MOD), \\
      basic system adapted for Modula--2 compiler\index{compiler} 
      and Atari computer,
      containing a garbage collector and file handling.
\end{enumerate}

Modules under 3 and 4 belong to the MAS kernel, 
modules under 1 and 2 constitute the MAS interpreter and parser.
Under 3 only an example configuration is given.
The MAS configuration\index{configuration}
set up is discussed in a later section.


\section{Implementation Issues of the LISP Interpreter} %---------

The idea of combining an ALGOL\index{ALGOL} like 
programming language\index{language} with LISP\index{LISP} 
is borrowed from A.C. Hearn's RLISP\index{RLISP}, which is part of the 
Reduce\index{Reduce} computer algebra system \cite{Hearn87}.
Our LISP interpreter is also influenced by SLISP\index{SLISP} 
(Standard LISP) \cite{Marti78}.
The actual implementation\index{implementation} of the interpreter
followed the book `LISP' of \cite{Stoyan84}.
A similar approach, implementing LISP in BCPL\index{BCPL}, 
was persuaded by \cite{FiN77}.

The current implementation\index{implementation} uses the 
MAS storage\index{storage} management and
input\index{input} /output\index{output} management which have 
their origin in the
ALDES / SAC-2 Basic and List Processing System by 
\cite{CoL80}, \cite{Loos76}. 

The symbol\index{symbol} handling was first done by the 
ALDES / SAC-2 Symbol System,
which uses an unbalanced tree for the symbol table.
In the present version ($\geq 0.6$) we use 
a hash table with balanced symbol tree entries.
Therefore the generation of alphabetical lists 
(as in the HELP command) needs some more time as 
in the previous system.
Without the specification component
there are typically less than 100 -- 200 symbols defined,
since sub--procedures in compiled code\index{compiled! code} 
which are not accessible from the interpreter do not count.
With the specifications of algebraic structures loaded 
about 700 -- 1000 symbols are defined.
In contrast in a running Reduce system about 4000 symbols and
2000 functions are defined.

The variable binding mechanism is the so called `deep access' binding
using a linear list  for the symbols and values 
(ALIST\index{ALIST}).
At the moment there are typically less than 50 values bound to symbols,
since variables in compiled code are not stored in the ALIST.
The MAS parser performs static scope anlysis and declares 
textualy local variables, but at LISP level 
dynamic scope is implemented.

The minimal MAS executable module is about 90 KB code. 
This includes storage management, input / output, symbol handling,
LISP interpreter, specification component and the parser. 
Not included are the 
arithmetic\index{arithmetic} routines.
In contrast XLISP is about 76 KB,
microEMACS 3.8 is about 80KB,
muSIMP-86 is about 57 KB, 
the muLISP\index{muLISP}-87 kernel is about 50 KB 
and SLISP\index{SLISP}/370 is about 50 KB of code. 

A full fledged MAS including arbitrary precision arithmetic,
a polynomial system, two Gr\"obner bases packages, a 
numerical\index{numeric} 
differential equation solver is about 176 KB.
In contrast Derive\index{Derive} is about 209 KB, the
Reduce\index{Reduce} savefile is about 610 KB 
( + 213 KB for PSL\index{PSL})
and the bare Reduce (without factorizer and integrator)
is reported to be about 459 KB.


\subsection{LISP to Modula--2 Interface} %------------

The interface between LISP and the compiled code\index{compiled! code} 
is realized with
the Modula--2 procedure types\index{procedure! type}\index{type}. 
The procedure code pointers are stored in the property list
of a symbol together with some signature information. 
Upon application of such a function symbol, the procedure 
is restored, the actual parameters are supplied and the
procedure is called. 

A simplified example of this mechanism is explained by
the following Modula--2 code piece:

\begin{verbatim}
       TYPE procf1 = PROCEDURE(LIST): LIST;
       PROCEDURE name(a: LIST): LIST; 
                 BEGIN  ... RETURN(x) END;
       VAR   f: procf1;
             a: ADDRESS;
             l: LIST;
       BEGIN a:=ADDRESS(name); ...
             f:=procf1(a);
             l:=f(2); ...
\end{verbatim}

With \verb/a:=ADDRESS(name)/ the code pointer of the 
function `name'
is saved in a, and can further be stored in the property 
list  of a symbol. 
Later an executable function can be restored with
\verb/f:=procf1(a)/ and can then be executed like any other 
function: \verb/l:=f(2)/.

In this example the user himself is responsible for
using the correct type conversion \verb/procf1/. 
For execution it is absolutely necessary that the number and 
types\index{type} of 
the actual and formal arguments are identical.
For this MAS exports type dependent functions for the 
declaration of compiled code\index{compiled! code} 
for interactive\index{interactive} usage.

Such a declaration looks like
\begin{verbatim}
       FROM MASLISPU IMPORT Compiledf1;
       FROM MASSTOR IMPORT FIRST; 
       Compiledf1(FIRST,"CAR");
\end{verbatim}
here the compiled function FIRST\index{FIRST} 
(with 1 input parameter)
is made available as LISP function CAR\index{CAR}.
And provisions are made to prevent CAR from being
called with the wrong number of arguments.
The Modula--2 compiler itself checks that the type of the 
function FIRST matches the type of the first parameter
of `Compiledf1'.
So the procedure types are an incredibly 
helpful feature of Modula--2. 


\subsection{Configuration Management} %--------------------

Despite of the large amount of available procedures
it seems necessary to provide some mechanisms
to select only the ones which one is actually interested in.
The Modula--2 procedure types together with 
the MAS interpreter design allow for a transparent 
configuration management.
\index{configuration}\index{procedure! type}\index{interpreter}

The association of a compiled procedure with 
a function symbol of the MAS language is accomplished
in a way described in the section on LISP implementation.
\index{compiled! procedure}\index{language}

In this section we will first discuss some 
key aspects of the MAS configuration management and then
we will give a sample listing of a `load module'.

In the MAS main program a procedure named 
\verb/InitExternals/ is called, which in turn activates
several other \verb*/InitExternals / procedures.
The name externals indicates code that is not required to run
the LISP kernel. 
\index{kernel}\index{InitExternals}

With the InitExternals procedures any desired configuration 
of the MAS system can be achieved. For example
if no arithmetic routines are required 
their declaration can be left out from the InitExternals.
Or if only Gr\"obner bases are to be studied, one 
can include declarations of the respective procedures.

Four points should be observed:

{\em first}, the complete {\bf type checking mechanism} of Modula--2
\index{type! checking}
is in effect. The compiler will detect discrepancies
between the declaration of the procedures and their usage.
Consider the procedure \verb/IWRITE/. 
In the import list it is specified from which 
module IWRITE is to be taken, here \verb/SACI/.
Then it is used as input to the 
\verb/Compiledp1/ procedure. If accidentally some other
procedure is used (p.e. \verb/Compiledp2/) then the 
compiler will complain about a type mismatch error. 

{\em second}, the linker will take care that all 
\index{linker}
subroutines used in the IWRITE procedure are 
collected together for the executable program. 
\index{executable program}
So if only a top level procedure is made accessible to
LISP, the linker looks for all {\bf lower level routines}
required to execute the top level routine.
\index{lower level routine}

{\em third}, the configuration of the MAS system can be done
using a {\bf familiar program development system}.
It is not necessary to learn about a special configuration
manager. Simply specify all required routines in 
the InitExternals and re--link the MAS main program and you have
a fitting MAS system.
\index{relink}

{\em fourth}, only the 
{\bf minimal number} of procedures is packed together.
On other LISP systems or LISP based computer 
algebra systems the whole packages (or modules) 
are put together, since it is not distinguished between
used (accessible) and unused (not accessible) procedures.
\index{optimized linking}\index{package}

A listing of part of the arithmetic 
InitExternals is shown:

{\small
\begin{verbatim}
      IMPLEMENTATION MODULE MASLOADA;

      FROM MASLISPU IMPORT Compiledp1, ...

      FROM SACI IMPORT IWRITE, IREAD, INEG, IPROD, ISUM, IDIF,
                       IQ, IREM, IQR, ISIGNF, IABSF, IEXP, 
                       ICOMP, IGCD, ILCM, IRAND, ILWRIT;
 
      FROM SACRN IMPORT RNWRIT, RNDWR, RNREAD, RNSIGN, RNCOMP, 
                        RNNEG, RNABS, RNINT, RNRED, 
                        RNSUM, RNDIF, RNPROD, RNQ;

      PROCEDURE InitExternalsA;
      (*Tell Modula about external compiled procedures. *)
      BEGIN 
      (*1*) (*from SACI. *)
            Compiledp1(IWRITE,"IWRITE");
            Compiledp1(ILWRIT,"ILWRIT");
            Compiledf0(IREAD,"IREAD");
            Compiledf1(ISIGNF,"ISIGN");
            Compiledf2(ICOMP,"ICOMP");
            Compiledf1(INEG,"INEG");
            ... 
            Compiledf2(IGCD,"IGCD");
            Compiledf2(ILCM,"ILCM");
            Compiledf1(IRAND,"IRAND");
      (*2*) (*from SACRN. *)
            Compiledp2(RNDWR,"RNDWR");
            Compiledp1(RNWRIT,"RNWRIT");
            Compiledf0(RNREAD,"RNREAD");
            Compiledf2(RNRED,"RNRED");
            ...
            Compiledf1(RNSIGN,"RNSIGN");
            Compiledf2(RNDIF,"RNDIF");
            Compiledf2(RNPROD,"RNPROD");
            Compiledf2(RNQ,"RNQ");
      (*3*) (*from MASAPF. *) ...
      (*4*) (*from SACPRIM. *) ...
      (*5*) (*from MASF. *) ...
      (*9*) END InitExternalsA;

      END MASLOADA.
\end{verbatim}
}
\index{integer}\index{rational number}\index{floating point}
\index{integer! factorization}\index{numeric}


\section{Libraries} %---------------------

The libraries are organized in groups, which are placed in 
separate directories. The currently available libraries are summarized 
in the sequel.
Besides the SAC, DIP and MAS libraries also any other Modula--2 
program libraries can be interfaced to the MAS system.
\index{library}


\subsection{Kernel} 

The kernel is contained in the directory \verb/MASKERN/. 
\index{kernel}

\begin{quote}
\begin{obeylines} 
 List Tools 
 MAS Basic I/O System 
 MAS BIOS Utility 
 MAS Configuration 
 MAS Elementary Functions 
 MAS Error 
 MAS Signal Handling 
 MAS Storage 
 MAS mtc [Modula-2 to C] 
 Portability 
 SAC Basic I/O System 
 SAC List Processing 
 System Informations 
 clock 
 kpathsearch 
 readline 
 MAS Signal Handling 
 Setjmp 
\end{obeylines}
\index{storage management}\index{input}\index{output}
\index{interpreter}\index{parser}\index{list! processing}
\index{symbol! handling}
\end{quote}


\subsection{Interpreter, LISP, Main Program} 

The LISP interpreter, the parser and the main program are contained in 
the directories \verb/MASLISP/ and \verb/MASMAIN/. 
\index{interpreter}\index{main program}

\begin{quote}
\begin{obeylines} 
 Aldes Parser 
 MAS Lisp 
 MAS Lisp Utility 
 MAS Parser 
 MAS Representation 
 MAS Specification 
 MAS Symbol 
 MAS/SAC Symbol System 2
 Modula Global Variable Implementation Module
 SAC Symbol System 
 SAC Symbol 2 

 MAS Load 
 MAS Load A
 MAS Load B
 MAS Load C
 MAS Load D
 MAS Load E
 MAS Load Symmetric Functions 
 MAS Load J
 MAS Load L
 MAS Load M
 MAS Load Q
 MAS Load Syzygy 
 MAS Utility 
 MAS Symbol to DIP 
 MAS Logic Configuration Implementation Module
 MAS Logic Demonstration Implementation Module
 Masload Polynomial Equation Simplify
\end{obeylines}
\index{interpreter}\index{parser}
\index{symbol! handling}
\end{quote}


\subsection{Basic arithmetic}

The basic artihmetic is contained in the directory \verb/MASARITH/. 
\index{basic arithmetic}\index{arithmetic}

\begin{quote}
\begin{obeylines} 
 MAS Arbitrary Precision Floating Point 
 MAS Complex Number 
 MAS Combinatorial System 
 MAS Floating Point 
 MAS Integer 
 MAS Octonion Number 
 MAS Quaternion Number 
 MAS Rational Number 
 MAS Set 
 SAC Combinatorical System 
 SAC Digit 
 SAC Integer 
 SAC Modular Digit and Integer 
 SAC Factorization and Prime Number 
 SAC Rational Number 
 SAC Set 
\end{obeylines}
\index{digit}\index{modular integer}
\index{integer}\index{rational number}
\index{integer! factorization}\index{set of integer}
\index{floating point}
\end{quote}


\subsection{Polynomial arithmetic}

The polynomial arithmetic is contained in the directory \verb/MASPOLY/. 
\index{polynomial! arithmetic}

\begin{quote}
\begin{obeylines}
 DIP Common Polynomial System 
 DIP Integral 
 DIP Integer Polynomial 
 DIP Rational 
 DIP Rational Number Polynomial 
 DIP Termorder Optimization 
 SAC Dense Polynomial 
 SAC Integer Polynomial System 
 SAC Modular Polynomial 
 SAC Polynomial System 
 SAC Rational Polynomial 
\end{obeylines}
\index{recursive polynomial}
\index{distributive polynomial}
\end{quote}


\subsection{Ring theory, algebraic geometry}

The modules for ring theory and algebraic geometry are contained in 
the directories \verb/SACRING/ and \verb/MASRING/. 
\index{ring}

\begin{quote}
\begin{obeylines}
 SAC Algebraic Number Field 
 SAC Extensions 1 
 SAC Extensions 2 
 SAC Extensions 3 
 SAC Extensions 4 
 SAC Extensions 5 
 SAC Extensions 6 
 SAC Extensions 7 
 SAC Extensions 8 
 SAC Modular Univariate Polynomial Factorization 
 SAC Polynomial Factorization 
 SAC Polynomial GCD and RES System 
 SAC Polynomial Real Root 
 SAC Univariate Polynomial Factorization 

 DIP Ideal Decomposition 0 System 
 DIP Dimension 
 DIP GCD 
 DIP Ideal System 
 DIP Integral D-Groebner Bases 
 DIP Integral Groebner Bases 
 DIP Rational Function 
 DIP Rational Groebner Bases 
 DIP Ideal Real Root System 
 DIP Zero Dimensional Ideal 
 MAS Finite Field 
 MAS Polynomial GCD and RES System 
 Universal Groebner Bases 
\end{obeylines}
\index{greatest common divisor}\index{resultant}
\index{algebraic number}\index{real root! isolation}
\index{Buchberger algorithm}\index{polynomial! ideals}
\index{ideal! decomposition}\index{roots! of ideals}
\index{systems of equations}
\end{quote}


\subsection{Non-commutative Polynomials}

The non-commutative polynomial arithmetic is contained in the 
directory \verb/MASNC/. 
\index{non-commutative polynomial}

\begin{quote}
\begin{obeylines}
 DIP Groebner bases for non noetherian polynomial rings 
 DIP Exterior Algebra 
 MAS Non-commutative Product 
 MAS Non-commutative Center 
 MAS Non-commutative Groebner Bases 
\end{obeylines}
\index{non-commutative polynomial}
\end{quote}


\subsection{Arbitrary domain Polynomials}

The arbitrary domain polynomial arithmetic and the 
comprehensive Gr\"obner base package are contained in the 
directory \verb/MASDOM/. 

\begin{quote}
\begin{obeylines}
 Arbitrary Domain Tools
 Comprehensive-Groebner-Bases Applications 
 Comprehensive-Groebner-Bases Data-Structures 
 Comprehensive-Groebner-Bases Utility Functions 
 Comprehensive-Groebner-Bases Main Programms 
 Comprehensive-Groebner-Bases Miscellaneous Programs
 Comprehensive-Groebner-Bases System 
 DIP Arbitrary Domain 
 DIP Arbitrary Domain Groebner Basis 
 DIP Decompositional Groebner Bases 
 DIP Domain D-Groebner Bases 
 DIP Groebner Bases 
 Distributive Polynomials Tools
 MAS Domain Algebraic Number 
 MAS Domain Arbitrary Precision Floating Point 
 MAS Domain Complex Number 
 MAS Domain Finite Field 
 MAS Domain Integer 
 MAS Domain Integral Polynomial 
 MAS Domain Modular Digit 
 MAS Domain Modular Integer 
 MAS Domain Octonion Number 
 MAS Domain Quaternion Number 
 MAS Domain Rational Function 
 MAS Domain Rational Number 
 MAS Domain Rational Polynomial 
 MAS Arbitrary Domain 
\end{obeylines}
\index{arbitrary domain! polynomial}
\index{comprehensive Gr\"obner base}
\end{quote}


\subsection{Module Arithmetic}

The linear algebra packages, the syzygy package and the 
polynomial invariants package are contained in the 
directory \verb/MASMODUL/. 
\index{linear algebra}\index{syzygy}
\index{polynomial invariants}\index{invariant polynomials}

\begin{quote}
\begin{obeylines}
 G-Symmetric Integral Polynomial System 
 G-Symmetric Rational Polynomial System 
 MAS Linear Algebra Integer 
 MAS Linear Algebra Rational Number 
 Noether Polynomial System 
 SAC Linear Diophantine Equation System 
 Substitution Group Polynomial System 
 Symmetric Functions 
 Syzygy Functions 
 Syzygy Groebner Base 
 Syzygy Utility Programs 
 Syzygy Main Programs 
 DIP Rational Extended Groebner Bases 
\end{obeylines}
\index{module! arithmetic}
\end{quote}


\subsection{Involutive Bases}

The involutive bases package is contained in the 
directory \verb/MASIB/. 
\index{involutive bases}

\begin{quote}
\begin{obeylines}
 Arbitrary domain extra definition module
 DIP Common Polynomial System in the sense of Janet
 DIP Decompositional Involutive Bases 
 DIP Common Polynomial System in the sense of Janet
 DIP Integral Polynomial System in the sense of Janet
 DIP Rational Numbers Polynomial in the sense of Janet
\end{obeylines}
\index{involutive bases}
\end{quote}


\subsection{Real root counting}

The Real root counting package is contained in the 
directory \verb/MASROOT/. 
\index{real root counting}
\index{root counting}

\begin{quote}
\begin{obeylines}
 Linear algebra definition module
 Real Root Arbitrary Domain
 Real Root Integral
 Real Root Univariate Arbitrary Domain
 Real Root Univariate Integral
\end{obeylines}
\index{root counting}
\end{quote}


\subsection{Logic formulas and quantifier elimination}

The first order logic formulas and quantifier elimination 
package is contained in the directory \verb/MASLOG/. 
\index{logic formulas}
\index{quantifier elimination}

\begin{quote}
\begin{obeylines}
 Maslog 
 Maslog Demonstration 
 Maslog Base 
 Maslog Input Output System 
 Polynomial Equation Base 
 Polynomial Equation Simplification 
 Real Quantifier Elimination with Parametric Real Root Count
 Type Formula 
\end{obeylines}
\index{logic formulas}
\index{quantifier elimination}
\end{quote}


