\documentclass{article}
\usepackage{../../src/scripts/tex/axiom}
\begin{document}
\title{\$SPAD/src/algebra Developer Notes}
\author{Timothy Daly}
\maketitle
\begin{abstract}
This file contains a random collection of facts about Axiom
intended for developers. It talks about directory structure,
internal representations, debugging tools, and gives a cookbook
for using CVS. There is nothing of interest for the end user.
\end{abstract}
\eject
\tableofcontents
\eject
\begin{verbatim}
*
***** ** ** *** ****** ** * *
* * * * * * * ** ** ** **
* * * * * * ** *** **
****** * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
***** * ** ** *** **** ** *** ***
*
\end{verbatim}
\section{Tools}
\subsection{cvs}
\begin{verbatim}
This assumes that you have set up ssh on the Savannah site.
CVS does not use a password. You have to log onto the Savannah
site and set up a public key. This requires you to:
a) set up a local public key:
ssh-keygen -b 1024 -t rsa1
b) open a browser
c) nagivate to the savannah page that has your personal keys
d) open .ssh/identity.pub
e) cut .ssh/identity.pub
f) paste it into your personal key list on savannah
h) go have a beer (the page takes an hour or two to update)
Once you have a working key you should be able to do the cvs login.
If it prompts you for a password the key is not working.
If it prompts you to ``Enter the passphrase for RSA key'' then the cvs
login will work.
I maintain a directory where I work (call this WORK)
/home/axiomgnu/new
and a directory for CVS (call this GOLD)
/axiom
When I want to export a set of changes I do the following steps:
0) MAKE SURE THE ~/.ssh/config FILE IS CORRECT:
(you should only need to do this once.
you need to change the User= field)
Host *.gnu.org
Protocol=1
Compression=yes
CompressionLevel=3
User=axiom
StrictHostKeyChecking=no
PreferredAuthentications=publickey,password
NumberOfPasswordPrompts=2
1) MAKE SURE THE SHELL VARIABLES ARE OK:
(normally set in .bashrc)
export CVS_RSH=ssh
export CVSROOT=:pserver:axiom@subversions.gnu.org:/cvsroot/axiom
^^^^^
change this to your id
2) MAKE SURE YOU'RE LOGGED IN:
(i keep a session open all the time but it doesn't seem to care
if you login again. i'm not sure what login does, actually)
cvs login
3) IF YOU WANT A FRESH COPY FOR THE FIRST TIME OR AT ANY TIME:
(you only need to do this the first time but you can erase
your whole axiom subtree and refresh it again doing this.
note that i work as root so i can update /. Most rational
people are smarter than me and work as a regular user so
you have to change the instructions for cd. But you knew that)
cd /
cvs co axiom
4) MAKE SURE THAT GOLD, MY LOCAL CVS COPY, IS UP TO DATE:
(i maintain an exact copy of the CVS repository and only make
changes to it when i want to export the changes. that way i
won't export my working tree by accident. my working tree is
normally badly broken.
The update command makes sure that you have all of the changes
other people might have made and checked in. you have to merge
your changes carefully so you don't step on other people's work.
So be sure to run update BEFORE you copy files to GOLD)
cd /axiom
cvs update
5) COPY THE CHANGED FILES FROM THE WORK TREE TO THE GOLD TREE:
(This is an example for updating the *.daase files.
You basically are changing your GOLD tree to reflect the
way you want CVS to look once you check in all of the files.
Since you want to check in your new daase files this will do it)
cp /home/axiomgnu/new/src/share/algebra/*.daase /axiom/src/share/algebra
6) IF A FILE IS NEW (e.g. src/interp/foo.lisp.pamphlet) THEN:
(If you create a file you need to "put it under CVS control"
CVS only cares about files you explicitly add or delete.
If you make a new file and copy it to GOLD you need to do this.
Don't do the "cvs add" in your WORK directory. The cvs add
command updates the files in the CVS directory and you won't
have them in your WORK directory.
Notice that you do the "cvs add" in the directory where the
file was added (hence, the cd commands).
cd /axiom/src/interp
cvs add -m"some pithy comment" foo.lisp.pamphlet
cd /axiom
7) IF A FILE IS DELETED (e.g. src/interp/foo.lisp.pamphlet) THEN:
(you have to delete the file from the GOLD directory BEFORE you
do a "cvs remove". The "cvs remove" will update the files in
the CVS directory
Notice that you do the "cvs remove" in the directory where the
file was deleted (hence, the cd commands).
cd /axiom/src/interp
rm foo.lisp.pamphlet
cvs remove foo.lisp.pamphlet
cd /axiom
8) IF A DIRECTORY IS NEW (e.g. foodir) THEN:
(this will put "foodir" under CVS control. It will also create
foodir/CVS as a directory with a bunch of control files in the
foodir/CVS directory. Don't mess with the control files.
(there are a bunch of special rules about directories.
empty directories are not downloaded by update.)
(NOTE: THERE IS NO WAY TO DELETE A DIRECTORY)
cd /axiom/src
mkdir foodir
cvs add -m "pithy comment" foodir
cd /axiom
9) edit CHANGELOG:
(The CHANGELOG is there so we have some clue what changed.
CVS also keeps track of this but I haven't figured out the
details yet so the CHANGELOG is a manual file for the moment
CHANGELOG is already under CVS control so it will get uploaded
when you do the checkin.)
cd /axiom
emacs -nw CHANGELOG
(add a date, initials, and pithy comment, save it, and exit)
10) CHECK IN THE CHANGES
(This will actually change the savannah CVS repository.
The "cvs ci" command will recurse thru all of the lower
subdirectories and look for changed files. It will change
the host versions of those files to agree with your copy.
If somebody else has changed a file while you were busy
screwing around then the checkin MAY complain (if it can't
merge the changes)
cd /axiom
cvs ci -m"pithy comment"
Congrats. You've now done your first real damage to the production
image. Please be very careful as this is a world-readable copy and
we don't want to ship nonsense. Test EVERYTHING, no matter how trivial
the change, BEFORE you upload. But I didn't need to tell you that :-)
\end{verbatim}
\section{Common Lisps}
\subsection{GCL}
Axiom was ported to run under AKCL which was a common lisp
developed by Bill Schelter. He started with KCL (Kyoto Common
Lisp) and, since he lived and worked in Austin, Texas, named
his version AKCL (Austin-Kyoto Common Lisp). Bill worked under
contract to the Scratchpad group at IBM Research. I was the
primary developer for system internals so Bill and I worked
closely together on a lot of issues. After Axiom was sold to
NAG Bill continued to develop AKCL and it eventually became
GCL (Gnu Common Lisp).
In order to port Axiom to run on GCL we need to do several things.
First, we need to apply a few patches. These patches enlarge the
default stack size, remove the startup banner, link with Axiom's
socket library, and rename collectfn.
The issue with the stack size is probably bogus. At one point the
system was running out of stack space but the problem was due to
a recursive expansion of a macro and no amount of stack space
would be sufficient. This patch remains at the moment but should
probably be removed and tested.
The startup banner is an issue because we plan to run under
various frontend programs like Texmacs and the Magnus ZLC.
We need to just output a single prompt.
Axiom has a socket library because at the time it was developed under
AKCL there was not socket code in Lisp. There is still not a standard
common lisp socket library but I believe all common lisps have a way
to manipulate sockets. This code should be rewritten in lisp
and [[#+]] for each common lisp.
The collectfn file is a major optimization under GCL. When collectfn
is loaded and the lisp compiler is run then collectfn will output
a [[.fn]] file. The second time the compiler is invoked the [[.fn]]
file is consulted to determine the actual types of arguments used.
Function calling is highly optimized using this type information
so that fast function calling occurs. Axiom should be built one
time to create the [[int/*/*.fn]] files. It should then be rebuilt
using the cached [[.fn]] files. I will automate this process into
the Makefiles in the future.
GCL implementation will have a major porting problem to brand new
platforms. The compiler strategy is to output C code, compile it
using GCC, and dynamically link the machine code to the running
image. This requires deep knowledge of the symbol tables used
by the native linker for each system. In general this is a hard
problem that requires a lot of expertise. Bill Schelter and I
spent a lot of time and effort making this work for each port.
The magic knowledge is not written down anywhere and I no longer
remember the details.
\subsection{CCL}
When Axiom was sold to NAG it was ported to CCL (Codemist Common
Lisp) which is not, strictly speaking, a common lisp implementation.
It contains just enough common lisp to support Axiom and, as I'm
a great believer in simple code, it only needed a small subset of
a full common lisp.
CCL can be considered the best way to get Axiom running on a new
architecture as the porting issues are minimal.
CCL is a byte-interpreter implementation and has both the
positive and negative aspects of that design choice. The positive
aspect is that porting the code to run on new architectures is
very simple. Once the CCL byte-code interpreter is running
then Axiom is running. The saved-system image is pure byte-codes
and is completely system independent.
The negative aspects are that it is slow and the garbage collector
appears broken. Compiling the Axiom library files on an file-by-file
basis takes about 1 hour on GCL and about 12 hours on CCL. Compiling
all of the Axiom library files in the same image (as opposed to
starting a new image per file) still takes about 1 hour on GCL.
It never finishes in CCL. Indeed it stops doing useful work after
about the 40th file (out of several hundred).
When Axiom became open source I moved the system back to GCL
because I could not understand how to build a CCL system. I plan
to revisit this in the future and document the process so others
can follow it as well as build Makefiles to automate it.
\subsection{CMU CL}
CMU CL grew out of the Carnegie-Mellon University SPICE project.
That project studied the issues involved in building an optimizing
compiler for common lisp. Axiom, back when it was Scratchpad at IBM,
ran on CMU CL. Indeed, a lot of the lisp-level optimizations are
due to use of the CMU CL compiler and the disassemble function.
\subsection{Franz Lisp}
Axiom, as Scratchpad, ran on Franz Lisp.
\subsection{Lucid Common Lisp}
Axiom, as Scratchpad, ran on Lucid Common Lisp.
\subsection{Symbolics Common Lisp}
Axiom, as Scratchpad, ran on Symbolics Common Lisp.
\subsection{Golden Common Lisp}
Axiom, as Scratchpad, ran on Golden Common Lisp.
This was a PC version of Common Lisp which appears to have died.
\subsection{VM/LISP 370}
Axiom, as Scratchpad, ran on VM/Lisp 370. This was an IBM version
of lisp and was not a common lisp. The [[.daase]] random access
file format is an artifact of running on this lisp.
\subsection{Maclisp}
Axiom, as Scratchpad, ran on Maclisp. This was an early MIT version
of lisp and is not common lisp. Many of the funny function names
that have slightly different semantics than their common lisp
counterparts still exist in the system as macros due to this
lisp.
\section{Databases}
\subsection{libcheck}
The databases are built from the [[.KAF]] files in the [[.NRLIB]] directories.
([[.KAF]] files are random access files).
[[INTERP.EXPOSED]] is a file that names all of the CDPs (Category, Domain,
and Packages) and classifies them. Only some CDPs are exposed because
most are used to implement algebra and are not intended to be user level
functions. Exposing all of the functions causes much ambiguity.
There is a function called libcheck (see [[src/interp/util.lisp.pamphlet]])
that will check [[NRLIBs]] vs [[INTERP.EXPOSED]]. This is only partially
functional as I see that changes were made to the system which broke
this function.
The libcheck function requires an absolute pathname to the int directory
so call it thus:
[[--> )lisp (libcheck "/axiom/int/algebra")]]
The main reason this function is broken is that the system now gets
exposure information from src/algebra/exposed.lsp.pamphlet. It appears
that [[INTERP.EXPOSED.pamphlet]] is no longer used (although I made sure
that both files have the same information). I'm going to modify libcheck
to use exposed.lsp in the future and eliminate all references in the
system to [[INTERP.EXPOSED]].
For the moment, however, the libcheck function is quite useful.
It used to be run during system build because I frequently ran into
database problems and this function would alert me to that fact.
I'll add it back into the Makefile once I elide [[INTERP.EXPOSED]].
\subsection{asq}
Axiom has several databases which contain information about domains,
categories, and packages. The databases are in a compressed format
and are organized as random-access files using numeric index values
so it is hard to get at the stored information. However, there is a
command-line query function called asq (ask) that knows the format
of the files and can be used for stand-alone queries. For instance,
if you know the abbreviation for a domain but want to know what
source file generated that domain you can say:
\begin{verbatim}
asq -so FOOBAR
\end{verbatim}
and it will tell you the name of the algebra source file that
defines FOOBAR.
\section{Axiom internal representations}
\begin{verbatim}
PRIMITIVE REPRESENTATIONS OF AXIOM OBJECTS
There are several primitive representations in axiom. These are:
boolean
this is represented as a lisp boolean
integer
this is represented as a lisp integer
small integer
this is represented as a lisp integer
small float
this is represented as a lisp float
list
this is represented as a lisp list
vector
this is represented as a lisp vector
record
there are 3 cases:
records of 1 element are represented as a pair (element . nil)
records of 2 element are represented as a pair (element1 . element2)
records of 3 or more are represented as vectors #
mapping
mappings are a spadcallable object. they are represented as a pair
(lispfn . env)
where the env is usually a type object. spadcall rips this pair open
and applies the lispfn to its args with env as the last arg.
union
there are 2 cases
if the object can be determined by a lisp predicate (eg integer)
then the union is just the object (eg 3) itself since we can use
lisp to decide which branch of the union the object belongs to.
that is, 3 is of the integer branch in union(list,integer)
if the object cannot be determined then the object is wrapped into
a pair where the car of the pair is the union branch name and the
cdr of the pair is the object. that is, given union(a:SUP,b:POLY(INT))
x might be (a . x)
note: if no tags are given in the union the system uses consecutive
integers, thus union(SUP,POLY(INT)) will give a pair of (1 . x) or
(2 . x) depending on the type of x
other types are built up of compositions of these primitive types.
thus a sparse univariate polynomial (SUP) over the integers
x**2+1
is represented as
Term := Record(k:NonNegativeInteger,c:R)
Rep := List Term
that is, the representation is a list of terms where each term is a
record whose first field is a nonnegative integer (the exponent) and
the second field is a member of the coefficient ring. since this is
a record of length 2 it is represented as a pair. thus, the internal
form of this polynomial is:
((2 . 1) (0 . 1))
a more complex object (recursively defined) is POLY(INT). given
x**2+1
as a POLY(INT) we look at its representation and see:
D := SparseUnivariatePolynomial($)
VPoly := Record(v:VarSet,ts:D)
Rep := Union(R,VPoly)
so first we find that we are a member of the second form of the union and
since this is an untagged union the system uses 2 as the tag. thus the
first level of internal representation is:
( 2 . )
next we need to define the VPoly object. VPolys are records of length 2
so we know they are represented by a pair. the car of the pair is a VarSet.
the cdr is a D which is a SparseUnivariatePolynomial. Thus we consider this
to be a poly in x (at the top level) and we get:
( 2 . ( x . ))
the SUP is over the SparseMultivariatePolynomials (SMP) so the representation
is recursive. Since an SUP is represented as a list of
(non-negative int . coefficient)
one per term and we have 2 terms we know the next level of structure is:
( 2 . ( x . (( 2 . ) ( 0 . ))))
the SMP is just the integers so it fits into the first branch of the union
and each SMP looks like:
( uniontag . value )
in this case, being the first branch we get
( 2 . ( x . (( 2 . ( 1 . 1 )) ( 0 . ( 1 . 1 )))))
as the internal representation of
x**2 + 1
what could be easier?
\end{verbatim}
\section{axiom command}
The axiom command will eventually be a shell script. At the moment
it is just a copy of the interpsys image. However the whole Axiom
system consists of several processes and the axiom command starts
these processes. The shell script will transparently replace the
axiom executable image which will be renamed to [[spadsys]].
\section{debugsys}
The "debugsys" executable is the "interpsys" image but it is
built using the interpreted lisp code rather than using compiled
lisp code. This will make it slower but may, in certain cases,
give much better feedback in case of errors. If you find you need
to use debugsys you're really doing deep debugging. It isn't useful
for much else. It can be started by typing:
\begin{verbatim}
export AXIOM=/home/axiomgnu/new/mnt/linux
/home/axiomgnu/new/obj/linux/bin/debugpsys
\end{verbatim}
Notice that this image lives in the "obj" subtree. It is not
shipped with the "final" system image as only developers could
find it useful.
\section{Understanding a compiled function}
Suppose we stop a program at a function call to some low level lisp function,
say ONEP. We can do that by entering
\begin{verbatim}
)trace ONEP )break
\end{verbatim}
at the Axiom command prompt. Or at the lisp prompt:
\begin{verbatim}
(trace (ONEP :entry (break)))
\end{verbatim}
Next we execute some function that will
eventually call ONEP thus:
\begin{verbatim}
p := numeric %pi
Break: onep
Broken at ONEP. Type :H for Help.
BOOT>>
\end{verbatim}
We have stopped and entered a lisp command prompt. We can enter any
lisp expression here and there are commands that begin with a ``:''
character. ``:b'' requests a backtrace of the call stack, thus:
\begin{verbatim}
BOOT>>:b
Backtrace: funcall > system:top-level > restart > /read > |upLET| > eval > |Pi| > |newGoGet| > |newGoGet| > ONEP
\end{verbatim}
Here we see that the function ONEP was called by the function newGoGet.
Notice that the name is surrounded by vertical bars. Vertical bars are
a common lisp escape sequence used to allow non-standard characters to
occur in symbol names. Common lisp is not case sensitive. Boot code is
case sensitive. Thus symbol names that were written in Boot tend to have
escape sequence characters around the name.
Now that we see the simple backtrace we can ask for a more complex one.
The command is ``:bt''. It shows more detail about each level of call
on the invocation history stack (ihs) including the function name, its
arguments and the depth of the invocation history stack ([ihs=13]):
\begin{verbatim}
BOOT>>:bt
#0 ONEP {1=nil,} [ihs=13]
#1 newGoGet {g3629=("0" (# 45 . |char|)),loc1=# 0 . |coerce|)),loc1=(# 0 . |c...} [ihs=11]
#3 Pi {g109299=nil,loc1=nil,loc2=#,loc3=|Pi|,loc4=15,loc5=#} [ihs=9]
#5 upLET {t=(# # (# (#} [ihs=4]
BOOT>>:bl
>> (LAMBDA-BLOCK ONEP (&REST X) ...)():
X : (1)
NIL
\end{verbatim}
We can ask to see the local variables that are used at the current
level of the invocation history stack. The command is ``:bl'' thus:
\begin{verbatim}
BOOT>>:bl
>> (LAMBDA-BLOCK ONEP (&REST X) ...)():
X : (1)
NIL
\end{verbatim}
We can move up the stack one level at a time looking at the function
that called the current function (the previous function) using ``:p'' thus:
\begin{verbatim}
BOOT>>:p
Broken at |NEWGOGET|.
\end{verbatim}
And again, we can look at the variables that can be accessed locally:
\begin{verbatim}
BOOT>>:bl
>> newGoGet():
Local0(G3629): (0 (# 45 . char))
Local(1): #
Local(2): 0
Local(3): #
Local(4): 1
NIL
\end{verbatim}
Here we see that the newGoGet function is calling the function named
CHAR;char;S\$;20 which is a mangled form of the name of the original
spad function. To decode this name we can see that the CHAR portion
is used to identify the domain where the function lives. This domain,
CHAR, comes from the source file ``string.spad'' which ultimately lives
in ``src/algebra/string.spad.pamphlet''. To discover this we use the
Axiom ``asq'' command with the ``-so'' (sourcefile) option at a
standard shell prompt (NOT in the lisp prompt) thus:
\begin{verbatim}
asq -so CHAR
string.spad
\end{verbatim}
If we look at the code in the string.spad.pamphlet file we find the
following code signature:
\begin{verbatim}
char: String -> %
++ char(s) provides a character from a string s of length one.
\end{verbatim}
and it's implementation code:
\begin{verbatim}
char(s:String) ==
(#s) = 1 => s(minIndex s) pretend %
error "String is not a single character"
\end{verbatim}
The string.spad file can be compiled at the command prompt. In particular,
we can compile only the CHAR domain out of this file thus:
\begin{verbatim}
)co string.spad )con CHAR
\end{verbatim}
This will produce a directory called CHAR.NRLIB containing 3 files:
\begin{verbatim}
ls CHAR.NRLIB
code.lsp index.KAF info
\end{verbatim}
The info file contains information used by the spad compiler. We can
ignore it for now.
The index.KAF file contains information that will go into the various
Axiom database (.daase) files. The KAF file format is a random access
file. The first entry is an integer that will be an index into the
file that can be used in an operating system call to seek. In this
case it will be an index which is the last used byte in the file.
Go to the last expression in the file and we find:
\begin{verbatim}
(
("slot1Info" 0 11302)
("documentation" 0 9179)
("ancestors" 0 9036)
("parents" 0 9010)
("abbreviation" 0 9005)
("predicates" 0 NIL)
("attributes" 0 NIL)
("signaturesAndLocals" 0 8156)
("superDomain" 0 NIL)
("operationAlist" 0 7207)
("modemaps" 0 6037)
("sourceFile" 0 5994)
("constructorCategory" 0 5434)
("constructorModemap" 0 4840)
("constructorKind" 0 4831)
("constructorForm" 0 4817)
("NILADIC" 0 4768)
("compilerInfo" 0 2093)
("loadTimeStuff" 0 20))
\end{verbatim}
This is a list of triples. Each triple has two interesting parts, the
name of the data and the seek index of the data in the index.KAF file.
So, for instance, if you want to know what source file contains this
domain you can start at the top of the index.KAF file, move ahead 5994
bytes and you will be at the start of the string:
\begin{verbatim}
"/usr/local/axiom/src/algebra/string.spad"
\end{verbatim}
The information in the index.KAF files are collected up into the
special databases (the .daase files). The stand-alone ``asq'' function
can query these databases and answer questions. The kind of questions
you can ask are the names in the list above.
The third file in the CHAR.NRLIB directory is the code.lsp file. This
is the actual common lisp code that will be executed as a result of
calling the various spad functions. The spad code from the char command
was:
\begin{verbatim}
char(s:String) ==
(#s) = 1 => s(minIndex s) pretend %
error "String is not a single character"
\end{verbatim}
which got compiled into the common lisp code:
\begin{verbatim}
(DEFUN |CHAR;char;S$;20| (|s| |$|)
(COND
((EQL (QCSIZE |s|) 1)
(SPADCALL |s|
(SPADCALL |s| (QREFELT |$| 47))
(QREFELT |$| 48)))
((QUOTE T)
(|error| "String is not a single character"))))
\end{verbatim}
To understand what is going on here we need to understand the low level
details of Axiom's interface to Common Lisp. The ``Q'' functions are
strongly typed (Quick) versions of standard common lisp functions.
QCSIZE is defined in src/interp/vmlisp.lisp.pamphlet thus:
\begin{verbatim}
(defmacro qcsize (x)
`(the fixnum (length (the simple-string ,x))))
\end{verbatim}
This macro will compute the length of a string.
QREFELT is defined in the same file as:
\begin{verbatim}
(defmacro qrefelt (vec ind)
`(svref ,vec ,ind))
\end{verbatim}
This macro will return the element of a vector.
SPADCALL is defined in src/interp/macros.lisp.pamphlet as:
\begin{verbatim}
(defmacro SPADCALL (&rest L)
(let ((args (butlast l)) (fn (car (last l))) (gi (gensym)))
`(let ((,gi ,fn)) (the (values t) (funcall (car ,gi) ,@args (cdr ,gi))))
))
\end{verbatim}
This macro will call the last value of the argument list as a function
and give it everything but the last argument as arguments to the function.
There are confusing historical reasons for this I won't go into here.
So you can see that these are simply macros that will expand into
highly optimizable (the optimizations depend on the abilities of the
common lisp compiler) common lisp code.
The common lisp code computes the length of the string s. If the length
is 1 then we call the minIndex function from string on s. The minIndex
function is found by looking "in the domain". The compiler changes the
minIndex function call into a reference into a vector. The 47th element
of the vector contains the function minIndex.
\begin{verbatim}
(SPADCALL |s| (QREFELT |$| 47))
\end{verbatim}
This code is equivalent (ignoring the gensyms) to the call
\begin{verbatim}
(minIndex s)
\end{verbatim}
The \$ symbol refers to the domain. At runtime this amounts to a lookup
of the ``infovec''. The compile-time infovec shown here:
\begin{verbatim}
(MAKEPROP
(QUOTE |Character|)
(QUOTE |infovec|)
(LIST
(QUOTE
#(NIL
NIL
NIL
NIL
NIL
NIL
(QUOTE |Rep|)
(|List| 28)
(|PrimitiveArray| 28)
(0 . |construct|)
(QUOTE |OutChars|)
(QUOTE |minChar|)
(|Boolean|)
|CHAR;=;2$B;1|
|CHAR;<;2$B;2|
(|NonNegativeInteger|)
|CHAR;size;Nni;3|
(|Integer|)
|CHAR;char;I$;6|
(|PositiveInteger|)
|CHAR;index;Pi$;4|
|CHAR;ord;$I;7|
|CHAR;lookup;$Pi;5|
(5 . |coerce|)
|CHAR;random;$;8|
|CHAR;space;$;9|
|CHAR;quote;$;10|
|CHAR;escape;$;11|
(|OutputForm|)
|CHAR;coerce;$Of;12|
(|CharacterClass|)
(10 . |digit|)
(|Character|)
(14 . |member?|)
|CHAR;digit?;$B;13|
(20 . |hexDigit|)
|CHAR;hexDigit?;$B;14|
(24 . |upperCase|)
|CHAR;upperCase?;$B;15|
(28 . |lowerCase|)
|CHAR;lowerCase?;$B;16|
(32 . |alphabetic|)
|CHAR;alphabetic?;$B;17|
(36 . |alphanumeric|)
|CHAR;alphanumeric?;$B;18|
(|String|)
|CHAR;latex;$S;19|
(40 . |minIndex|)
(45 . |elt|)
|CHAR;char;S$;20|
|CHAR;upperCase;2$;21|
|CHAR;lowerCase;2$;22|
(|SingleInteger|)))
(QUOTE
#(|~=| 51 |upperCase?| 57 |upperCase| 62 |space| 67 |size| 71 |random|
75 |quote| 79 |ord| 83 |min| 88 |max| 94 |lowerCase?| 100 |lowerCase|
105 |lookup| 110 |latex| 115 |index| 120 |hexDigit?| 125 |hash| 130
|escape| 135 |digit?| 139 |coerce| 144 |char| 149 |alphanumeric?| 159
|alphabetic?| 164 |>=| 169 |>| 175 |=| 181 |<=| 187 |<| 193))
(QUOTE NIL)
(CONS
(|makeByteWordVec2| 1 (QUOTE (0 0 0 0 0 0)))
(CONS
(QUOTE #(NIL |OrderedSet&| NIL |SetCategory&| |BasicType&| NIL))
(CONS
(QUOTE
#((|OrderedFinite|)
(|OrderedSet|)
(|Finite|)
(|SetCategory|)
(|BasicType|)
(|CoercibleTo| 28)))
(|makeByteWordVec2| 52
(QUOTE
(1 8 0 7 9 1 6 0 17 23 0 30 0 31 2 30 12 32 0 33 0 30 0 35 0 30
0 37 0 30 0 39 0 30 0 41 0 30 0 43 1 45 17 0 47 2 45 32 0 17 48
2 0 12 0 0 1 1 0 12 0 38 1 0 0 0 50 0 0 0 25 0 0 15 16 0 0 0 24
0 0 0 26 1 0 17 0 21 2 0 0 0 0 1 2 0 0 0 0 1 1 0 12 0 40 1 0 0 0
51 1 0 19 0 22 1 0 45 0 46 1 0 0 19 20 1 0 12 0 36 1 0 52 0 1 0
0 0 27 1 0 12 0 34 1 0 28 0 29 1 0 0 45 49 1 0 0 17 18 1 0 12 0
44 1 0 12 0 42 2 0 12 0 0 1 2 0 12 0 0 1 2 0 12 0 0 13 2 0 12 0
0 1 2 0 12 0 0 14))))))
(QUOTE |lookupComplete|)))
\end{verbatim}
Which is a 5 element list. This contains all kinds of information used at
runtime by the compiled routines. In particular, functions are looked up
at runtime in the first element of the infovec list. This first element
contains 53 items (in this domain). Item 47 is
\begin{verbatim}
(40 . |minIndex|)
\end{verbatim}
which is the minIndex function we seek.
At runtime this infovec lives on the property list of the domain name.
The domain name of CHAR is Character. So we look on the property list
(a lisp a-list) thus:
\begin{verbatim}
BOOT>>(symbol-plist '|Character|)
(SYSTEM:DEBUG (#:G85875)
|infovec| (#
#
NIL
(#
#
# . #)
|lookupComplete|)
LOADED "/home/axiomgnu/new/mnt/linux/algebra/CHAR.o"
NILADIC T
PNAME "Character"
DATABASE #S(DATABASE
ABBREVIATION CHAR
ANCESTORS NIL
CONSTRUCTOR NIL
CONSTRUCTORCATEGORY 228064
CONSTRUCTORKIND |domain|
CONSTRUCTORMODEMAP 227069
COSIG (NIL)
DEFAULTDOMAIN NIL
MODEMAPS 227404
NILADIC T
OBJECT "CHAR"
OPERATIONALIST 226402
DOCUMENTATION 152634
CONSTRUCTORFORM 152626
ATTRIBUTES 154726
PREDICATES 154731
SOURCEFILE "string.spad"
PARENTS NIL
USERS NIL
DEPENDENTS NIL
SPARE NIL))
\end{verbatim}
This list is organized contains many runtime lookup items (notice the
PNAME entry is "Character", the LOADED entry says where the file came
from, the DATABASE structure entry has a bunch of database indicies
(see daase.lisp.pamphlet for the structure definition), etc).
Lets get the property list
\begin{verbatim}
BOOT>>(setq a (symbol-plist '|Character|))
(SYSTEM:DEBUG (#:G85875)
|infovec| (#
#
NIL
(#
#
# . #)
|lookupComplete|)
LOADED "/home/axiomgnu/new/mnt/linux/algebra/CHAR.o"
NILADIC T
PNAME "Character"
DATABASE #S(DATABASE
ABBREVIATION CHAR
ANCESTORS NIL
CONSTRUCTOR NIL
CONSTRUCTORCATEGORY 228064
CONSTRUCTORKIND |domain|
CONSTRUCTORMODEMAP 227069
COSIG (NIL)
DEFAULTDOMAIN NIL
MODEMAPS 227404
NILADIC T
OBJECT "CHAR"
OPERATIONALIST 226402
DOCUMENTATION 152634
CONSTRUCTORFORM 152626
ATTRIBUTES 154726
PREDICATES 154731
SOURCEFILE "string.spad"
PARENTS NIL
USERS NIL
DEPENDENTS NIL
SPARE NIL))
\end{verbatim}
Next we get the infovec value
\begin{verbatim}
BOOT>>(setq b (fourth a))
(#
#
NIL
(#
#
# . #)
|lookupComplete|)
\end{verbatim}
Then we get the function table
\begin{verbatim}
BOOT>>(setq c (car b))
#
\end{verbatim}
In this common lisp (GCL) the array is identified by it's memory address.
Notice that it has the right number of entries:
\begin{verbatim}
BOOT>>(length c)
53
\end{verbatim}
And we can ask for the 47th entry thus:
\begin{verbatim}
BOOT>>(elt c 47)
(40 . |minIndex|)
\end{verbatim}
Later we end up calling the 48th function (which is elt and
returns the actual character in the string). We ask for it:
\begin{verbatim}
BOOT>>(elt c 48)
(45 . |elt|)
\end{verbatim}
At this point we've reached the metal. Common lisp will evaluate
the macro-expanded functions and execute the proper code. Essentially
the compiler has changed all of our spad code into runtime table lookups.
\section{The axiom.input startup file}
If you add a file in your home directory called ``.axiom.input'' it will
be read and executed when Axiom starts. This is useful for various
reasons including setting various switches. Mine reads:
\begin{verbatim}
)lisp (pprint ``running /root/.axiom.input'')
)set quit unprotected
)set message autoload off
)set message startup off
\end{verbatim}
You can execute any command in .axiom.input. Be aware that this will
ALSO be run while you are doing a ``make'' so be careful what you ask to do.
\section{Where are Axiom symbols stored?}
You'd think that your question about where the symbol is interned
would be easy to answer but it is not. The top level loop uses Bill
Burge's dreaded zipper parser. You can see it in action by executing
the following sequence:
\begin{verbatim}
)lisp (setq $DALYMODE t) ;;; this is a special mode of the top level
;;; interpreter. If $DALYMODE is true then
;;; any top-level form that begins with an
;;; open-paren is considered a lisp expression.
;;; For almost everything I ever do I end up
;;; peeking at the lisp so this bit of magic helps.
(trace |intloopProcessString|) ;; from int-top.boot.pamphlet
(trace |intloopProcess|) ;; the third argument is the "zippered" input
(trace |intloopSpadProcess|) ;; now it is all clear, no? sigh.
(trace |phInterpret|) ;; from int-top.boot.pamphlet
(trace |intInterpretPform|) ;; from intint.lisp.pamphlet
(trace |processInteractive|) ;; from i-toplev.boot.pamphlet
(setq |$reportInstantiations| t) ;; shows what domains were created
(setq |$monitorNewWorld| t) ;; watch the interpreter resolve operations
(trace |processInteractive1|) ;; from i-toplev.boot.pamphlet
\end{verbatim}
ah HA! I remember now. There is the notion of a "frame" which is
basically a namespace in Axiom or an alist in Common Lisp. It is
possible to maintain different "frames" and move among them. There
is the notion of the current frame and it contains all the defined
variables. At any given time the current frame is available as
[[|$InteractiveFrame|]]. This variable is used in [[|processInteractive1|]].
If you do:
\begin{verbatim}
a:=7
(pprint |$InteractiveFrame|)
\end{verbatim}
you'll see |a| show up on the alist. When you do the
\begin{verbatim}
pgr:=MonoidRing(Polynomial PrimeField 5, Permutation Integer)
p:pgr:=1
\end{verbatim}
you'll see [[|p|]] show up with 2 other things: ([[|p|]] mode value)
where mode is the "type" of the variable. The value is the
internal value. In this case MonoidRing has an internal
representation. You can find out what the internal representation
of a MonoidRing is by first asking where the source file is:
\begin{verbatim}
(do this at a shell prompt, not in axiom)
asq -so MonoidRing ==> mring.spad
-- or -- in Axiom type:
)show MonoidRing
\end{verbatim}
and you'll see a line that reads:
\begin{verbatim}
Issue )edit (yourpath)/../../src/algebra/mring.spad
\end{verbatim}
If you look in mring.spad.pamphlet you'll see line 91 that reads:
\begin{verbatim}
Rep := List Term
\end{verbatim}
which says that we will store elements of type MonoidRing as a list
of Term objects. Term is defined in the same file (as a macro, which
is what [['==>']] means in spad files) on line 43:
\begin{verbatim}
Term ==> Record(coef: R, monom: M)
\end{verbatim}
which means that elements of a MonoidRing are Lists of Records.
The 'R' is defined on line 42 as the first argument to MonoidRing
which in this case is [['Polynomial PrimeField 5']]. The [['M']] is also
defined on line 42 as the second argument to MonoidRing and in this
case is [['Permutation Integer']]. So the real representation is
\begin{verbatim}
List Record(coef: Polynomial PrimeField 5, monom: Permutation Integer)
\end{verbatim}
In the [[|$InteractiveFrame|]] we printed out you can see in the |value|
field that the value is:
\begin{verbatim}
(|value| (|MonoidRing| (|Polynomial| (|PrimeField| 5)) (|Permutation| (|Integer|))) WRAPPED ((0 . 1) . #))
\end{verbatim}
which basically means that we know how the MonoidRing was constructed and
what it's current value is. The [[(0 . 1)]] likely means that this is the
zeroth (constant) term with a leading coefficient of 1. This is just a
guess as I haven't decoded the representation of either Polynomial PrimeField
or Permutation Integer. You can do the same deconstruction of these two
domains by setting
\begin{verbatim}
pi:=Permutation Integer
z:pi:=1
pp5:=Polynomial PrimeField 5
w:pp5:=1
and following the same steps as above:
(pprint |$InteractiveFrame|)
)show pi
(find the source file)
(find the representation and decode it)
(pprint |$InteractiveFrame|)
)show pp5
(find the source file)
(find the representation and decode it)
\end{verbatim}
Be sure to set [[$DALYMODE]] to nil if you plan to use Axiom for any
real computation. Otherwise every expression that begins with an
open-paren will go directly to lisp.
\section{Translating individual boot files to common lisp}
If you are making changes to boot code it is sometimes helpful to
check the generated lisp code to ensure it does what you want.
You can convert an individual boot file to common lisp using the
[[boottran::boottocl]] function:
\begin{verbatim}
)fin -- drop into common lisp
(boottran::boottocl "foo.boot")
\end{verbatim}
when you do this it creates a [[foo.clisp]] file in [[../../int/interp]]
Alternatively if you work from the pamphlet file the process is
more painful as you have to do
\begin{verbatim}
)cd (yourpath)/int/interp
)sys tangle ../../src/interp/foo.boot.pamphlet >foo.boot
)fin
(boottran::boottocl "foo.boot")
(restart)
\end{verbatim}
The [[)cd]] step tells axiom to cd to the [[int/interp]] subdirectory.
The [[)sys tangle...]] extracts the boot file from the pamphlet file
The [[)fin]] step drops into common lisp
The [[(bootran...]] converts the [[foo.boot]] file to [[foo.clisp]]
The [[(restart)]] re-enters the top level loop
\section{Directories}
For this discussion I assume that you have your system rooted
at [[/spad]] and was build to run on [[linux]]. These directories
may not yet be in the CVS tree but are documented here so they
make sense when the show up.
\vskip .25in
\noindent
[[The AXIOM variable]]
The usual setting of the AXIOM variable is [[/spad/mnt/linux]]. The
name is composed of three parts, the rooted path, in this case
[[/spad]], ``mnt'', and the system you are running, in this case
[[linux]]. Builds for other systems will have other system names.
\vskip .25in
\noindent
[[/spad]]
This is the usual root directory of the Axiom system. The name is
historical, a contraction of Scratchpad. This name can be anything
provided the shell variable AXIOM contains the new prefix.
\vskip .25in
\noindent
[[/spad/mnt]]
This is a directory which contains files which are specific to a
given platform. At a site that contains multiple platforms this
directory will contain a subdirectory for each type of platform
(e.g. linux, rios, ps2, rt, sun, etc).
\vskip .25in
\noindent
[[/spad/mnt/linux]]
This directory contains the complete copy of the Axiom system for
the linux system. This is the 'mount point' of the system.
Executable systems (for RedHat) are shipped relative to this
point. In what follows, the [[./]] refers to [[/spad/mnt/linux]].
\begin{verbatim}
*********************************************************************
There are several directories explained below. They are:
./bin -- user executables
./doc -- system documentation
./algebra -- algebra libraries
./lib -- system executables
./etc -- I haven't a clue....
*********************************************************************
\end{verbatim}
\subsection{The mnt/linux/bin directory}
\vskip .25in
\noindent
[[./bin]]
This is a directory of user executable commands, either at the top
level or thru certain Axiom system calls. Support executables live
in [[./lib]]
\vskip .25in
\noindent
[[./bin/htadd]]
This function adds pages to the Hyperdoc database (ht.db, which lives
in [[./doc/hypertex/pages]]; hypertex, since we have a penchant for these
things, is an historical name for Hyperdoc. The single word 'lawyers'
will probably explain away a lot of name changes.)
\vskip .25in
\noindent
[[./bin/spadsys]]
This is the Axiom interpreter. It is one of the functions started when
the user invokes the system using the spadsys command. Normally this
command is run under the control of sman ([[./lib/sman]]) and the console
is under the control of clef ([[./bin/clef]]), the wonderous command-line
editor. It is possible to start [[spadsys]] standalone but it will not
talk to [[Hyperdoc]] or [[graphics]]. Users who rlogin or use an ascii-only
terminal (for historical reasons, no doubt) can profit by invoking
[[spadsys]] directly rather than using [[./bin/axiom]]
\vskip .25in
\noindent
[[./bin/axiom]]
This is a shell script that spins the world. It kicks off a whole tree
of processes necessary to perform the X-related magic we do. It expects
the shell variable AXIOM to be set to the 'mount point' (usually to
[[/spad/mnt/linux]]).
\vskip .25in
\noindent
[[./bin/clef]]
This is the wonderous command-line editor used by Axiom. It can be used
in a stand-alone fashion if you wish.
\vskip .25in
\noindent
[[./bin/SPADEDFN]]
This script is invoked by the spad )fe command. It can be changed to
invoke your favorite editor. While you may invoke your editor, it may
not run (as in, yes, I can invoke the devil but will he come when I
call?)
\vskip .25in
\noindent
[[./bin/viewAlone]]
This is a function to run the graphics in a stand-alone fashion. The
Graphics package (an amazing contribution by several very talented
people, most notably Jim Wen and Jon Steinbach) is a C program that
communicates with Axiom thru sockets. It will, however, perform its
miracles unaided if invoked by the sufficiently chaste...
\vskip .25in
\noindent
[[./bin/hypertex]]
This is a function to run Hyperdoc (remember the penchant!) stand-alone.
The Hyperdoc package owes its existence to the efforts of J.M. Wiley and
Scott Morrison. This function works off 'pages' that live in
[[./doc/hypertex/pages]] and are referenced in the 'hyperdoc database'
called [[./doc/hypertex/pages/ht.db]] (for historical reasons, but you
knew that). It is possible for creative plagerists to figure out how
to write their own pages and add them to the database (see htadd above),
thus gaining fame far and wide...
\vskip .25in
\noindent
[[./bin/sys-init.lsp]]
This isn't a function, it is a file of lisp code that gets loaded
before Axiom starts. Thus, we distribute patches by adding lisp
(load ...) commands to this file. The sufficiently clever should
have a field day with this one. (All others should worship the
sufficiently clever and send them money, eh?)
\vskip .25in
\noindent
[[./bin/init.lsp]]
This isn't a function, it is a file of lisp code loaded iff (for the
non-mathematician, that means if and only if, but YOU knew that, eh?)
you start spadsys in this directory. The user can put a file of this
name in her home directory and it will get loaded at startup with
the probable effect of injecting luser errors into the running system.
sigh.
\subsection{The mnt/linux/doc directory}
\vskip .25in
\noindent
[[./doc]]
The doc subdirectory contains system documentation.
\vskip .25in
\noindent
[[./doc/command.list]]
This is a file of command completions used by clef when you hit the
tab key. This is a little known feature that will surprise someone
someday (hopefully pleasantly).
\vskip .25in
\noindent
[[./doc/book]]
This is an attempt at a book describing Axiom. It represents a
combination of fantasy, describing what never will be and history
(remember the penchant?) describing what was. Any description matching
what is may be regarded as failure of the imagination and ignored.
\vskip .25in
\noindent
[[./doc/compguide]]
This is an attempt to describe a compiler that doesn't exist, never
did exist, and never will exist. It makes for entertaining reading
so we included it.
\vskip .25in
\noindent
[[./doc/hypertex]]
This is the fabled Hyperdoc subdirectory where all of the pages and
the database live, along with several other obscure files needed to
make the wizards look good.
\vskip .25in
\noindent
[[./doc/hypertex/pages]]
This is where the 'pages' live. Each file ending in [[.ht]] contains
several pages related, if only by chance, to the same topic. You
may find it instructive to try to read some of these files. Hyperdoc
was learned by the 'campfire' method (sitting around the fire
passing along historical facts by word of mouth) and will probably
continue to propagate by the same method. Ye may become th' local
scribe and soothsayer if ye study the writings here below....
\vskip .25in
\noindent
[[./doc/hypertex/pages/rootpage.ht]]
This file is the magic 'first page' that gets displayed when
Hyperdoc starts. There is a macro (see [[./doc/hypertex/pages/util.ht]])
called /localinfo which is intended to allow the luser to add
her own pages without modifying the system copies. How this is
done was lost when the campfire got rained out.
\vskip .25in
\noindent
[[./doc/hypertex/pages/util.ht]]
This file contains the macros used to extend the system commands.
The syntax is hard to learn (it was hard to write, it ought to
be hard to learn, eh?).
\vskip .25in
\noindent
[[./doc/hypertex/pages/ht.db]]
This is the Hyperdoc database. It is updated using [[./bin/htadd]]
which must be run whenever a page in this directory gets changed.
The necessary arguments to htadd are obvious to those in the know.
\vskip .25in
\noindent
[[./doc/hypertex/bitmaps]]
There are several pretty bitmaps used as cursors, buttons and
general decorations that hide in this directory.
\vskip .25in
\noindent
[[./doc/hypertex/ht.files]]
This is a list of some Hyperdoc files. It seems to have no
purpose in life but it is useful as a koan, as in, What is
the length of half a list?
\vskip .25in
\noindent
[[./doc/hypertex/ht.db]]
Another copy of the Hyperdoc database. It isn't clear which
one is the real one so I guess we keep both. Maybe we'll
figure it out at the friday night campfire provided we don't
get too lit.
\vskip .25in
\noindent
[[./doc/hypertex/gloss.text]]
The text used in the glossary. Many magic words lie herein.
Some are spoken only by campfire gurus.
\vskip .25in
\noindent
[[./doc/library]]
This is a directory of Hyperdoc pages that can be freely smashed,
trashed and generally played with. It uses the /localinfo connection
to set up a 'library' containing Hyperdoc pages keyed to your
favorite textbook. It is interesting to set the shell variable\\
[[HTPATH=/spad/mnt/linux/doc/library:/spad/mnt/linux/doc/hypertex/pages]]
and then start Hyperdoc. See the file [[./doc/library/macros.ht]]
\vskip .25in
\noindent
[[./doc/msgs]]
This directory contains several 'message databases'; the only one
of which we seem to care about being s2-us.msgs but I can't swear
to it.
\vskip .25in
\noindent
[[./doc/spadhelp]]
This is a directory containing help information for a copy of the
system that once ran long ago and far away. It is kept for
historical reasons (programmers NEVER throw anything away).
\vskip .25in
\noindent
[[./doc/viewports]]
There are several dozen truly fine pictures in Axiom. We have
created them and hidden them here. Hyperdoc will insert them
at various places (where the text gets too boring, hopefully)
and you can click on them there. They get snarfed from here.
It is possible to view them with stand-alone graphics but don't
ask me how. I missed that campfire due to poisoned marshmellows.
\vskip .25in
\noindent
[[./doc/complang]]
This directory contains fantasy from the past as opposed to facts
from the future. Ignore it.
\vskip .25in
\noindent
[[./doc/ug]]
This directory left intentionally blank :-) (an old IBM joke).
\vskip .25in
\noindent
[[./doc/tex]]
These are the files necessary to create the famous goertler document.
If you figure hou how to use these please send us the instructions
and we will add a log to the campfire with your name on it (a rare
honor indeed as luser's names rarely reach the inner circle).
\vskip .25in
\noindent
[[./doc/htex]]
This directory contains the original tex-like source for the luser's
guide. There are many functions that munch on these between here and
paper but this is approximately where they start. If you do your own
algebra perchance you might document it like this. Figuring out the
syntax will also get your name into the inner circle (probably
connnected with a smirk :-) )
\vskip .25in
\noindent
[[./doc/newug]]
Please don't ask me. I couldn't begin to guess. You wouldn't believe
how many 'new' things there are that really aren't. We have more NEW
things than Madison Avenue has NEW laundry soap.
\vskip .25in
\noindent
[[./doc/gloss.text]]
This one is here because it is here. Existentially speaking, of course.
\vskip .25in
\noindent
[[./doc/submitted]]
This was what the htex files said before history was rewritten...
(and renamed?)
\subsection{The mnt/linux/algebra directory}
\vskip .25in
\noindent
[[./algebra]]
This is where all of the interesting action lives.
Each .NRLIB directory contains 2 files, a code.o and an index.KAF*
file. The code.o contains the executable algebra that gets loaded
into the system. The index.KAF* file contains all kinds of things
like signatures, source paths, properties and dried bat droppings.
The documentation for each of these can be reached by using the
BROWSE feature of Hyperdoc.
\vskip .25in
\noindent
[[./algebra/MODEMAP.DAASE]]
This is an inverted database that contains information gleaned from
the index.KAF* files. Without this there is no way to figure out
which .NRLIB file to load. This database is opened on startup
and kept open.
\vskip .25in
\noindent
[[./algebra/INTERP.EXPOSED]]
This is a control file for the interpeter that limits the number
of places to search for function names.
*********************************************************************
\subsection{The mnt/linux/lib directory}
\vskip .25in
\noindent
[[./lib]]
This directory contains functions that get loaded by the system.
Nothing in here is executable by the user but the system needs
these functions to run.
\vskip .25in
\noindent
[[./lib/htrefs]]\\
[[./lib/htsearch]]\\
[[./lib/hthits]]
These three functions are used to search the Hyperdoc pages.
There is no way in the current system to request a search of
those pages so these files are fascinating examples of history
in the making...
\vskip .25in
\noindent
[[./lib/hypertex]]
This is Hyperdoc. What is in a name?
\vskip .25in
\noindent
[[./lib/sman]]
This is sman, which comes before all. Methinks the name originated
as a contraction of superman, the name of a stack frame in a system
long ago and far away (VMLisp) chosen because a certain programmer had a
penchant for comic books when he was young.
\vskip .25in
\noindent
[[./lib/session]]\\
[[./lib/spadclient]]
These two files are processes started by sman for some reason or other.
I can never remember what they do or why. However, the campfire fails
to smoke if they don't work.
\vskip .25in
\noindent
[[./lib/viewman]]
This is the controlling function for the graphics.
\vskip .25in
\noindent
[[./lib/view2D]]
This is invoked when a 2 dimensional window is requested.
This is provided mostly for those math majors who never got over
the insights from flatland.
\vskip .25in
\noindent
[[./lib/view3D]]
This is invoked when a 3 dimensional window is requested.
Option IBM3634-A is required to convert your 2 dimensional
screen to 3 dimensions for realistic viewing. A mathematically
accurate, if somewhat more achievable, rendering can be had
on a color or monochrome crt without this upgrade.
\vskip .25in
\noindent
[[./lib/gloss.text]]\\
[[./lib/glosskey.text]]\\
[[./lib/glossdef.text]]
These are three files related to the glossary. The first ([[gloss.text]])
is the original glossary text. The second ([[glosskey.text]]) is a list
of terms and pointers into [[glossdef.text]]. The third ([[glossdef.text]] for
those math majors who can't count) is a list of definitions and pointers
back into the second (guess). These files are used by Hyperdoc.
\vskip .25in
\noindent
[[./lib/browsedb.lisp]]
This is the original file that creates an in-memory hash table used by
browse. It is used during system build time. We keep it here to ensure
that the bytes on this section of the disk have a well-defined orientation,
allowing us to compute the spin vectors of the individual magnetic domains.
This allows us to give Heisenburg a sense of direction (at least over the
long run).
\vskip .25in
\noindent
[[./lib/comdb.text]]\\
[[./lib/libdb.text]]
The first file ([[comdb.text]]) contains the so-called [[++]] (plus
plus) comments from the algebra files and pointers into the second
file. The second file ([[libdb.text]]) contains flags (constructor,
operation, attribute) and pointers into the first file. These files
are used by browse in Hyperdoc.
\vskip .25in
\noindent
[[./lib/loadmprotect]]\\
[[./lib/mprotect]]
This set of two files has been mercifully de-installed from the system.
They will, if used and despite the meaning behind the name, cause
random system reboots (yeah, HARDWARE reboots. don't ask me how, I'm
just the historian).
\vskip .25in
\noindent
[[./lib/SPADEDIT]]\\
[[./lib/fc]]\\
[[./lib/spadbuf]]\\
[[./lib/SPADEDFN]]\\
[[./lib/obey]]\\
[[./lib/ex2ht]]
I've drawn a blank; intentionally.
\subsection{The mnt/linux/lib directory}
\vskip .25in
\noindent
[[./etc]]
This directory intentionally left blank.
We just can't figure out WHY we intended to leave it blank.
Historical reasons, no doubt.
\section{Low Level Debugging Techniques}
It should be observed that Axiom is basically Common Lisp and
some very low level techniques can be used to find where problems
occur in algebra code. This section walks thru a small problem and
illustrates some techniques that can be used to find bugs. The
point of this exercise is to show a few techniques, not to show a
general method.
\subsection{The example bug}
Axiom can generate TeX output by typing:
\begin{verbatim}
)set output tex on
)end{verbatim}
Here we give an example of TeX output that contains a bug:
\begin{verbatim}
(1) -> )set output tex on
(1) -> radix(10**10,32)
Loading /axiom/mnt/linux/algebra/RADUTIL.o for package
RadixUtilities
Loading /axiom/mnt/linux/algebra/RADIX.o for domain RadixExpansion
Loading /axiom/mnt/linux/algebra/ANY1.o for package AnyFunctions1
Loading /axiom/mnt/linux/algebra/NONE1.o for package NoneFunctions1
Loading /axiom/mnt/linux/algebra/ANY.o for domain Any
Loading /axiom/mnt/linux/algebra/SEX.o for domain SExpression
(1) 9A0NP00
Loading /axiom/mnt/linux/algebra/TEX.o for domain TexFormat
Loading /axiom/mnt/linux/algebra/CCLASS.o for domain CharacterClass
Loading /axiom/mnt/linux/algebra/IBITS.o for domain IndexedBits
Loading /axiom/mnt/linux/algebra/UNISEG.o for domain
UniversalSegment
$$
9#\A0#\N#\P00
\leqno(1)
$$
Loading /axiom/mnt/linux/algebra/VOID.o for domain Void
Type: RadixExpansion 32
\end{verbatim}
The correct output should be:
\begin{verbatim}
$$
9A0NP00
\leqno(1)
$$
\end{verbatim}
So we need to figure out where the [[#\ ]] prefixes are being generated.
In the above code we can see various domains being loaded. These domains
are lisp code. Each domain lives in a subdirectory of its own. For example,
the ANY domain lives in [[ANY.NRLIB]]. The [[ANY.NRLIB]] directory contains a
common lisp file named [[code.lsp]]. The compiled form of this code [[ANY.o]]
is loaded whenever the domain Any is referenced. We can look at the lisp
code:
\begin{verbatim}
(/VERSIONCHECK 2)
(PUT (QUOTE |ANY;obj;$N;1|) (QUOTE |SPADreplace|) (QUOTE QCDR))
(DEFUN |ANY;obj;$N;1| (|x| $) (QCDR |x|))
(PUT (QUOTE |ANY;dom;$Se;2|) (QUOTE |SPADreplace|) (QUOTE QCAR))
(DEFUN |ANY;dom;$Se;2| (|x| $) (QCAR |x|))
(PUT (QUOTE |ANY;domainOf;$Of;3|) (QUOTE |SPADreplace|) (QUOTE QCAR))
(DEFUN |ANY;domainOf;$Of;3| (|x| $) (QCAR |x|))
(DEFUN |ANY;=;2$B;4| (|x| |y| $) (COND ((SPADCALL (QCAR |x|) (QCAR |y|) (QREFELT $ 17)) (EQ (QCDR |x|) (QCDR |y|))) ((QUOTE T) (QUOTE NIL))))
(DEFUN |ANY;objectOf;$Of;5| (|x| $) (|spad2BootCoerce| (QCDR |x|) (QCAR |x|) (SPADCALL (SPADCALL "OutputForm" (QREFELT $ 21)) (QREFELT $ 23))))
(DEFUN |ANY;showTypeInOutput;BS;6| (|b| $) (SEQ (SETELT $ 10 (SPADCALL |b| (QREFELT $ 9))) (EXIT (COND (|b| "Type of object will be displayed in output of a member of Any") ((QUOTE T) "Type of object will not be displayed in output of a member of Any")))))
(DEFUN |ANY;coerce;$Of;7| (|x| $) (PROG (|obj1| |p| |dom1| #0=#:G1426 |a| #1=#:G1427) (RETURN (SEQ (LETT |obj1| (SPADCALL |x| (QREFELT $ 24)) |ANY;coerce;$Of;7|) (COND ((NULL (SPADCALL (QREFELT $ 10) (QREFELT $ 26))) (EXIT |obj1|))) (LETT |dom1| (SEQ (LETT |p| (|prefix2String| (|devaluate| (QCAR |x|))) |ANY;coerce;$Of;7|) (EXIT (COND ((SPADCALL |p| (QREFELT $ 27)) (SPADCALL |p| (QREFELT $ 23))) ((QUOTE T) (SPADCALL |p| (QREFELT $ 29)))))) |ANY;coerce;$Of;7|) (EXIT (SPADCALL (CONS |obj1| (CONS ":" (PROGN (LETT #0# NIL |ANY;coerce;$Of;7|) (SEQ (LETT |a| NIL |ANY;coerce;$Of;7|) (LETT #1# |dom1| |ANY;coerce;$Of;7|) G190 (COND ((OR (ATOM #1#) (PROGN (LETT |a| (CAR #1#) |ANY;coerce;$Of;7|) NIL)) (GO G191))) (SEQ (EXIT (LETT #0# (CONS (SPADCALL |a| (QREFELT $ 30)) #0#) |ANY;coerce;$Of;7|))) (LETT #1# (CDR #1#) |ANY;coerce;$Of;7|) (GO G190) G191 (EXIT (NREVERSE0 #0#)))))) (QREFELT $ 31)))))))
(DEFUN |ANY;any;SeN$;8| (|domain| |object| $) (SEQ (COND ((|isValidType| |domain|) (CONS |domain| |object|)) ((QUOTE T) (SEQ (LETT |domain| (|devaluate| |domain|) |ANY;any;SeN$;8|) (EXIT (COND ((|isValidType| |domain|) (CONS |domain| |object|)) ((QUOTE T) (|error| "function any must have a domain as first argument")))))))))
(DEFUN |Any| NIL (PROG NIL (RETURN (PROG (#0=#:G1432) (RETURN (COND ((LETT #0# (HGET |$ConstructorCache| (QUOTE |Any|)) |Any|) (|CDRwithIncrement| (CDAR #0#))) ((QUOTE T) (UNWIND-PROTECT (PROG1 (CDDAR (HPUT |$ConstructorCache| (QUOTE |Any|) (LIST (CONS NIL (CONS 1 (|Any;|)))))) (LETT #0# T |Any|)) (COND ((NOT #0#) (HREM |$ConstructorCache| (QUOTE |Any|))))))))))))
(DEFUN |Any;| NIL (PROG (|dv$| $ |pv$|) (RETURN (PROGN (LETT |dv$| (QUOTE (|Any|)) . #0=(|Any|)) (LETT $ (GETREFV 35) . #0#) (QSETREFV $ 0 |dv$|) (QSETREFV $ 3 (LETT |pv$| (|buildPredVector| 0 0 NIL) . #0#)) (|haddProp| |$ConstructorCache| (QUOTE |Any|) NIL (CONS 1 $)) (|stuffDomainSlots| $) (QSETREFV $ 6 (|Record| (|:| |dm| (|SExpression|)) (|:| |ob| (|None|)))) (QSETREFV $ 10 (SPADCALL (QUOTE NIL) (QREFELT $ 9))) $))))
(MAKEPROP (QUOTE |Any|) (QUOTE |infovec|) (LIST (QUOTE #(NIL NIL NIL NIL NIL NIL (QUOTE |Rep|) (|Boolean|) (|Reference| 7) (0 . |ref|) (QUOTE |printTypeInOutputP|) (|None|) |ANY;obj;$N;1| (|SExpression|) |ANY;dom;$Se;2| (|OutputForm|) |ANY;domainOf;$Of;3| (5 . =) |ANY;=;2$B;4| (|String|) (|Symbol|) (11 . |coerce|) (|List| 20) (16 . |list|) |ANY;objectOf;$Of;5| |ANY;showTypeInOutput;BS;6| (21 . |deref|) (26 . |atom?|) (|List| $) (31 . |list|) (36 . |coerce|) (41 . |hconcat|) |ANY;coerce;$Of;7| |ANY;any;SeN$;8| (|SingleInteger|))) (QUOTE #(~= 46 |showTypeInOutput| 52 |objectOf| 57 |obj| 62 |latex| 67 |hash| 72 |domainOf| 77 |dom| 82 |coerce| 87 |any| 92 = 98)) (QUOTE NIL) (CONS (|makeByteWordVec2| 1 (QUOTE (0 0 0))) (CONS (QUOTE #(|SetCategory&| |BasicType&| NIL)) (CONS (QUOTE #((|SetCategory|) (|BasicType|) (|CoercibleTo| 15))) (|makeByteWordVec2| 34 (QUOTE (1 8 0 7 9 2 13 7 0 0 17 1 20 0 19 21 1 22 0 20 23 1 8 7 0 26 1 13 7 0 27 1 20 28 0 29 1 20 15 0 30 1 15 0 28 31 2 0 7 0 0 1 1 0 19 7 25 1 0 15 0 24 1 0 11 0 12 1 0 19 0 1 1 0 34 0 1 1 0 15 0 16 1 0 13 0 14 1 0 15 0 32 2 0 0 13 11 33 2 0 7 0 0 18)))))) (QUOTE |lookupComplete|)))
(MAKEPROP (QUOTE |Any|) (QUOTE NILADIC) T)
\end{verbatim}
We can ignore this information and focus on the functions that are
defined in this file. These functions can be traced with the usual
common lisp tracing facility. So lets create a file [[/tmp/debug.lisp]]
that contains a trace statement for each [[DEFUN]] in [[ANY.NRLIB/code.lsp]].
It looks like:
\begin{verbatim}
(trace |ANY1;retractable?;AB;1|)
(trace |ANY1;coerce;SA;2|)
(trace |ANY1;retractIfCan;AU;3|)
(trace |ANY1;retract;AS;4|)
(trace |AnyFunctions1|)
(trace |AnyFunctions1;|)
\end{verbatim}
We can now restart the axiom system, rerun the failing expression
(this will autoload ANY.o; alternatively we could hand-load the
[[ANY.NRLIB/code.lsp]] file), and then load our [[/tmp/debug.lisp]] file.
Now all of the functions in the [[ANY]] domain are traced and we can
watch the trace occur while the expression is evaluated. In this example
I've created a larger file that traces all of the loaded domains:
\begin{verbatim}
(trace |RADUTIL;radix;FIA;1|)
(trace |RadixUtilities|)
(trace |RadixUtilities;|)
(trace |RADIX;characteristic;Nni;1|)
(trace |RADIX;differentiate;2$;2|)
(trace |RADIX;Zero;$;3|)
(trace |RADIX;One;$;4|)
(trace |RADIX;-;2$;5|)
(trace |RADIX;+;3$;6|)
(trace |RADIX;-;3$;7|)
(trace |RADIX;*;I2$;8|)
(trace |RADIX;*;3$;9|)
(trace |RADIX;/;3$;10|)
(trace |RADIX;/;2I$;11|)
(trace |RADIX;<;2$B;12|)
(trace |RADIX;=;2$B;13|)
(trace |RADIX;numer;$I;14|)
(trace |RADIX;denom;$I;15|)
(trace |RADIX;coerce;$F;16|)
(trace |RADIX;coerce;I$;17|)
(trace |RADIX;coerce;F$;18|)
(trace |RADIX;retractIfCan;$U;19|)
(trace |RADIX;retractIfCan;$U;20|)
(trace |RADIX;ceiling;$I;21|)
(trace |RADIX;floor;$I;22|)
(trace |RADIX;wholePart;$I;23|)
(trace |RADIX;fractionPart;$F;24|)
(trace |RADIX;wholeRagits;$L;25|)
(trace |RADIX;fractRagits;$S;26|)
(trace |RADIX;prefixRagits;$L;27|)
(trace |RADIX;cycleRagits;$L;28|)
(trace |RADIX;wholeRadix;L$;29|)
(trace |RADIX;fractRadix;2L$;30|)
(trace |RADIX;intToExpr|)
(trace |RADIX;exprgroup|)
(trace |RADIX;intgroup|)
(trace |RADIX;overBar|)
(trace |RADIX;coerce;$Of;35|)
(trace |RADIX;checkRagits|)
(trace |RADIX;radixInt|)
(trace |RADIX;radixFrac|)
(trace |RadixExpansion|)
(trace |RadixExpansion;|)
(trace |ANY1;retractable?;AB;1|)
(trace |ANY1;coerce;SA;2|)
(trace |ANY1;retractIfCan;AU;3|)
(trace |ANY1;retract;AS;4|)
(trace |AnyFunctions1|)
(trace |AnyFunctions1;|)
(trace |NONE1;coerce;SN;1|)
(trace |NoneFunctions1|)
(trace |NoneFunctions1;|)
(trace |ANY;obj;$N;1|)
(trace |ANY;dom;$Se;2|)
(trace |ANY;domainOf;$Of;3|)
(trace |ANY;=;2$B;4|)
(trace |ANY;objectOf;$Of;5|)
(trace |ANY;showTypeInOutput;BS;6|)
(trace |ANY;coerce;$Of;7|)
(trace |ANY;any;SeN$;8|)
(trace |Any|)
(trace |Any;|)
(trace |SExpression|)
(trace |SExpression;|)
(trace |TEX;new;$;1|)
(trace |TEX;newWithNum|)
(trace |TEX;coerce;Of$;3|)
(trace |TEX;convert;OfI$;4|)
(trace |TEX;display;$IV;5|)
(trace |TEX;display;$V;6|)
(trace |TEX;prologue;$L;7|)
(trace |TEX;tex;$L;8|)
(trace |TEX;epilogue;$L;9|)
(trace |TEX;setPrologue!;$2L;10|)
(trace |TEX;setTex!;$2L;11|)
(trace |TEX;setEpilogue!;$2L;12|)
(trace |TEX;coerce;$Of;13|)
(trace |TEX;ungroup|)
(trace |TEX;postcondition|)
(trace |TEX;stringify|)
(trace |TEX;lineConcat|)
(trace |TEX;splitLong|)
(trace |TEX;splitLong1|)
(trace |TEX;group|)
(trace |TEX;addBraces|)
(trace |TEX;addBrackets|)
(trace |TEX;parenthesize|)
(trace |TEX;precondition|)
(trace |TEX;formatSpecial|)
(trace |TEX;formatPlex|)
(trace |TEX;formatMatrix|)
(trace |TEX;formatFunction|)
(trace |TEX;formatNullary|)
(trace |TEX;formatUnary|)
(trace |TEX;formatBinary|)
(trace |TEX;formatNary|)
(trace |TEX;formatNaryNoGroup|)
(trace |TEX;formatTex|)
(trace |TexFormat|)
(trace |TexFormat;|)
(trace |CCLASS;digit;$;1|)
(trace |CCLASS;hexDigit;$;2|)
(trace |CCLASS;upperCase;$;3|)
(trace |CCLASS;lowerCase;$;4|)
(trace |CCLASS;alphabetic;$;5|)
(trace |CCLASS;alphanumeric;$;6|)
(trace |CCLASS;=;2$B;7|)
(trace |CCLASS;member?;C$B;8|)
(trace |CCLASS;union;3$;9|)
(trace |CCLASS;intersect;3$;10|)
(trace |CCLASS;difference;3$;11|)
(trace |CCLASS;complement;2$;12|)
(trace |CCLASS;convert;$S;13|)
(trace |CCLASS;convert;$L;14|)
(trace |CCLASS;charClass;S$;15|)
(trace |CCLASS;charClass;L$;16|)
(trace |CCLASS;coerce;$Of;17|)
(trace |CCLASS;#;$Nni;18|)
(trace |CCLASS;empty;$;19|)
(trace |CCLASS;brace;$;20|)
(trace |CCLASS;insert!;C2$;21|)
(trace |CCLASS;remove!;C2$;22|)
(trace |CCLASS;inspect;$C;23|)
(trace |CCLASS;extract!;$C;24|)
(trace |CCLASS;map;M2$;25|)
(trace |CCLASS;map!;M2$;26|)
(trace |CCLASS;parts;$L;27|)
(trace |CharacterClass|)
(trace |CharacterClass;|)
(trace |IBITS;minIndex;$I;1|)
(trace |IBITS;range|)
(trace |IBITS;coerce;$Of;3|)
(trace |IBITS;new;NniB$;4|)
(trace |IBITS;empty;$;5|)
(trace |IBITS;copy;2$;6|)
(trace |IBITS;#;$Nni;7|)
(trace |IBITS;=;2$B;8|)
(trace |IBITS;<;2$B;9|)
(trace |IBITS;and;3$;10|)
(trace |IBITS;or;3$;11|)
(trace |IBITS;xor;3$;12|)
(trace |IBITS;setelt;$I2B;13|)
(trace |IBITS;elt;$IB;14|)
(trace |IBITS;Not;2$;15|)
(trace |IBITS;And;3$;16|)
(trace |IBITS;Or;3$;17|)
(trace |IndexedBits|)
(trace |IndexedBits;|)
(trace |UNISEG;segment;S$;1|)
(trace |UNISEG;segment;2S$;2|)
(trace |UNISEG;BY;$I$;3|)
(trace |UNISEG;lo;$S;4|)
(trace |UNISEG;low;$S;5|)
(trace |UNISEG;hasHi;$B;6|)
(trace |UNISEG;hi;$S;7|)
(trace |UNISEG;high;$S;8|)
(trace |UNISEG;incr;$I;9|)
(trace |UNISEG;SEGMENT;S$;10|)
(trace |UNISEG;SEGMENT;2S$;11|)
(trace |UNISEG;coerce;S$;12|)
(trace |UNISEG;convert;S$;13|)
(trace |UNISEG;=;2$B;14|)
(trace |UNISEG;coerce;$Of;15|)
(trace |UNISEG;expand;$S;16|)
(trace |UNISEG;map;M$S;17|)
(trace |UNISEG;plusInc|)
(trace |UNISEG;expand;LS;19|)
(trace |UNISEG;expand;LS;19!0|)
(trace |UniversalSegment|)
(trace |UniversalSegment;|)
\end{verbatim}
Now we rerun the function and get the trace output
\begin{verbatim}
(2) -> )lisp (load "/axiom/debug.lisp")
Value = T
(2) -> radix(10**10,32)
1> (|RadixUtilities|)
<1 (|RadixUtilities| #)
1> (|RadixExpansion| 32)
<1 (|RadixExpansion| #)
1> (|AnyFunctions1| #)
<1 (|AnyFunctions1| #)
1> (|RadixExpansion| 32)
<1 (|RadixExpansion| #)
1> (|RADIX;radixInt| 10000000000 32 #)
<1 (|RADIX;radixInt| (9 10 0 23 25 0 0))
1> (|RADIX;radixFrac| 0 1 32 #)
<1 (|RADIX;radixFrac| (NIL 0))
1> (|RadixExpansion| 32)
<1 (|RadixExpansion| #)
1> (|RADIX;intgroup| (9 10 0 23 25 0 0) #)
2> (|RADIX;intToExpr| 9 #)
<2 (|RADIX;intToExpr| 9)
2> (|RADIX;intToExpr| 10 #)
<2 (|RADIX;intToExpr| #\A)
2> (|RADIX;intToExpr| 0 #)
<2 (|RADIX;intToExpr| 0)
2> (|RADIX;intToExpr| 23 #)
<2 (|RADIX;intToExpr| #\N)
2> (|RADIX;intToExpr| 25 #)
<2 (|RADIX;intToExpr| #\P)
2> (|RADIX;intToExpr| 0 #)
<2 (|RADIX;intToExpr| 0)
2> (|RADIX;intToExpr| 0 #)
<2 (|RADIX;intToExpr| 0)
<1 (|RADIX;intgroup| (CONCAT 9 #\A 0 #\N #\P 0 0))
1> (|RADIX;exprgroup| ((CONCAT 9 #\A 0 #\N #\P 0 0)) #)
<1 (|RADIX;exprgroup| (CONCAT 9 #\A 0 #\N #\P 0 0))
(2) 9A0NP00
1> (|TexFormat|)
<1 (|TexFormat| #)
1> (|TexFormat|)
<1 (|TexFormat| #)
1> (|TEX;newWithNum| 2 #)
<1 (|TEX;newWithNum| #)
1> (|TEX;precondition| (CONCAT 9 #\A 0 #\N #\P 0 0) #)
<1 (|TEX;precondition| (CONCAT 9 #\A 0 #\N #\P 0 0))
1> (|TEX;formatTex| (CONCAT 9 #\A 0 #\N #\P 0 0) 0 #)
2> (|TEX;stringify| CONCAT #)
<2 (|TEX;stringify| "CONCAT")
2> (|TEX;formatSpecial| "CONCAT" (9 #\A 0 #\N #\P 0 0) 0 #)
3> (|TEX;formatNary| "" (9 #\A 0 #\N #\P 0 0) 0 #)
4> (|TEX;formatNaryNoGroup| "" (9 #\A 0 #\N #\P 0 0) 0 #)
5> (|TEX;formatTex| 9 0 #)
6> (|TEX;stringify| 9 #)
<6 (|TEX;stringify| "9")
<5 (|TEX;formatTex| "9")
5> (|TEX;formatTex| #\A 0 #)
6> (|TEX;stringify| #\A #)
<6 (|TEX;stringify| "#\\A")
6> (|IBITS;range| # 35 #)
<6 (|IBITS;range| 35)
<5 (|TEX;formatTex| "#\\A")
5> (|TEX;formatTex| 0 0 #)
6> (|TEX;stringify| 0 #)
<6 (|TEX;stringify| "0")
<5 (|TEX;formatTex| "0")
5> (|TEX;formatTex| #\N 0 #)
6> (|TEX;stringify| #\N #)
<6 (|TEX;stringify| "#\\N")
6> (|IBITS;range| # 35 #)
<6 (|IBITS;range| 35)
<5 (|TEX;formatTex| "#\\N")
5> (|TEX;formatTex| #\P 0 #)
6> (|TEX;stringify| #\P #)
<6 (|TEX;stringify| "#\\P")
6> (|IBITS;range| # 35 #)
<6 (|IBITS;range| 35)
<5 (|TEX;formatTex| "#\\P")
5> (|TEX;formatTex| 0 0 #)
6> (|TEX;stringify| 0 #)
<6 (|TEX;stringify| "0")
<5 (|TEX;formatTex| "0")
5> (|TEX;formatTex| 0 0 #)
6> (|TEX;stringify| 0 #)
<6 (|TEX;stringify| "0")
<5 (|TEX;formatTex| "0")
<4 (|TEX;formatNaryNoGroup| "9#\\A0#\\N#\\P00")
4> (|TEX;group| "9#\\A0#\\N#\\P00" #)
<4 (|TEX;group| "{9#\\A0#\\N#\\P00}")
<3 (|TEX;formatNary| "{9#\\A0#\\N#\\P00}")
<2 (|TEX;formatSpecial| "{9#\\A0#\\N#\\P00}")
<1 (|TEX;formatTex| "{9#\\A0#\\N#\\P00}")
1> (|TEX;postcondition| "{9#\\A0#\\N#\\P00}" #)
2> (|TEX;ungroup| "{9#\\A0#\\N#\\P00}" #)
<2 (|TEX;ungroup| "9#\\A0#\\N#\\P00")
<1 (|TEX;postcondition| "9#\\A0#\\N#\\P00")
$$
1> (|TEX;splitLong| "9#\\A0#\\N#\\P00" 77 #)
2> (|TEX;splitLong1| "9#\\A0#\\N#\\P00" 77 #)
3> (|TEX;lineConcat| "9#\\A0#\\N#\\P00 " NIL #)
<3 (|TEX;lineConcat| ("9#\\A0#\\N#\\P00 "))
<2 (|TEX;splitLong1| ("9#\\A0#\\N#\\P00 "))
<1 (|TEX;splitLong| ("9#\\A0#\\N#\\P00 "))
9#\A0#\N#\P00
\leqno(2)
$$
Type: RadixExpansion 32
\end{verbatim}
Notice the call that reads:
\begin{verbatim}
2> (|RADIX;intToExpr| 10 #)
<2 (|RADIX;intToExpr| #\A)
\end{verbatim}
This means that calling [[|RADIX;intToExpr|]] with the number [[10]]
and "the domain vector" generates the failing character [[#\A]].
If we had the domain vector in a variable we could hand-execute this
algebra function directly and watch it fail. So we go to the file
[[RADIX.NRLIB/code.lsp] which contains the definition of [[|RADIX;intToExpr|]].
The definition is:
\begin{verbatim}
(DEFUN |RADIX;intToExpr| (|i| $)
(COND
((< |i| 10)
(SPADCALL |i| (QREFELT $ 66)))
((QUOTE T)
(SPADCALL
(SPADCALL
(QREFELT $ 64)
(+ (- |i| 10) (SPADCALL (QREFELT $ 64) (QREFELT $ 68)))
(QREFELT $ 70))
(QREFELT $ 71)))))
\end{verbatim}
We can put this definition into our [[/tmp/debug.lisp]] file and modify
it to capture the domain vector passed in the [[$]] variable thus:
\begin{verbatim}
(DEFUN |RADIX;intToExpr| (|i| $)
(setq tpd $)
(COND
((< |i| 10)
(SPADCALL |i| (QREFELT $ 66)))
((QUOTE T)
(SPADCALL
(SPADCALL
(QREFELT $ 64)
(+ (- |i| 10) (SPADCALL (QREFELT $ 64) (QREFELT $ 68)))
(QREFELT $ 70))
(QREFELT $ 71)))))
\end{verbatim}
Now when this function is executed the [[tpd]] variable will contain the
value of [[$]], the domain vector. So we load [[/tmp/debug.lisp]] again
to redefine [[|RADIX;intToExpr|]] and re-execute the function. The trace
results will be the same but now the global variable [[tpd]] will have
the domain vector:
\begin{verbatim}
(4) -> (identity tpd)
Value = #
\end{verbatim}
Now we can use common lisp to step the [[|RADIX;intToExpr|]] function:
\begin{verbatim}
(4) -> (step (|RADIX;intToExpr| 10 tpd))
Type ? and a newline for help.
(|RADIX;intToExpr| 10 ...) ?
Stepper commands:
n (or N or Newline): advances to the next form.
s (or S): skips the form.
p (or P): pretty-prints the form.
f (or F) FUNCTION: skips until the FUNCTION is called.
q (or Q): quits.
u (or U): goes up to the enclosing form.
e (or E) FORM: evaluates the FORM and prints the value(s).
r (or R) FORM: evaluates the FORM and returns the value(s).
b (or B): prints backtrace.
?: prints this.
(|RADIX;intToExpr| 10 ...)
10
TPD
= #
(SYSTEM::TRACE-CALL (QUOTE #:G1624) ...)
(QUOTE #:G1624)
SYSTEM::ARGS
= (10 #)
(QUOTE T)
(QUOTE T)
(QUOTE (CONS # ...))
(QUOTE T)
(QUOTE (CONS # ...))
(LET (#) ...)
(QUOTE (10 #))
T
= T
1> (LET (#) ...)
(QUOTE (10 #))
(CONS (QUOTE |RADIX;intToExpr|) ...)
(QUOTE |RADIX;intToExpr|)
SYSTEM::ARGLIST
= (10 #)
= (|RADIX;intToExpr| 10 ...)
= (|RADIX;intToExpr| 10 ...)
(|RADIX;intToExpr| 10 ...)
(SETQ TPD ...)
$
= #
= #
(COND (# #) ...)
(< |i| ...)
|i|
= 10
10
= NIL
(QUOTE T)
(SPADCALL (SPADCALL # ...) ...)
(LET (#) ...)
(QREFELT $ ...)
(SVREF $ ...)
$
= #
71
= (# . #)
= (# . #)
(THE (VALUES T) ...)
(FUNCALL (CAR #:G1776) ...)
(CAR #:G1776)
#:G1776
= (# . #)
= #
(SPADCALL (QREFELT $ ...) ...)
(LET (#) ...)
(QREFELT $ ...)
(SVREF $ ...)
$
= #
70
= (# . #)
= (# . #)
(THE (VALUES T) ...)
(FUNCALL (CAR #:G1777) ...)
(CAR #:G1777)
#:G1777
= (# . #)
= #
(QREFELT $ ...)
(SVREF $ ...)
$
= #
64
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
(+ (- |i| ...) ...)
(- |i| ...)
|i|
= 10
10
= 0
(SPADCALL (QREFELT $ ...) ...)
(LET (#) ...)
(QREFELT $ ...)
(SVREF $ ...)
$
= #
68
= (# . #)
= (# . #)
(THE (VALUES T) ...)
(FUNCALL (CAR #:G1778) ...)
(CAR #:G1778)
#:G1778
= (# . #)
= #
(QREFELT $ ...)
(SVREF $ ...)
$
= #
64
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
(CDR #:G1778)
#:G1778
= (# . #)
= #
= 1
= 1
= 1
= 1
= 1
(CDR #:G1777)
#:G1777
= (# . #)
= #
= 65
= 65
= 65
= 65
(CDR #:G1776)
#:G1776
= (# . #)
= #
= #\A
= #\A
= #\A
= #\A
= #\A
<1 (LET (# #) ...)
(QUOTE (10 #))
(QUOTE (#\A))
(CONS (QUOTE |RADIX;intToExpr|) ...)
(QUOTE |RADIX;intToExpr|)
VALUES
= (#\A)
= (|RADIX;intToExpr| #\A)
= (|RADIX;intToExpr| #\A)
(|RADIX;intToExpr| #\A)
= #\A
= #\A
Value = #\A
(4) ->
\end{verbatim}
If we examine the source code for this function in [[int/algebra/radix.spad]]
we find:
\begin{verbatim}
ALPHAS : String := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
intToExpr(i:I): OUT ==
-- computes a digit for bases between 11 and 36
i < 10 => i :: OUT
elt(ALPHAS,(i-10) + minIndex(ALPHAS)) :: OUT
\end{verbatim}
We do some lookups by hand to find out what functions are being called
from the domain vectors thus:
\begin{verbatim}
(4) -> )lisp (qrefelt tpd 68)
Value = (# . #)
\end{verbatim}
The [[#\A]] value appears as a result of a call to
[[|CHAR;coerce;$Of;12|]]. We can look in [[CHAR.NRLIB/code.lsp]]
for this function and continue our descent into the code. The
function looks like:
\begin{verbatim}
(DEFUN |CHAR;coerce;$Of;12| (|c| $)
(ELT (QREFELT $ 10) (+ (QREFELT $ 11) (SPADCALL |c| (QREFELT $ 21)))))
\end{verbatim}
Again we need to get the domain vector, this time from the CHAR domain.
The domain vector has all of the information about a domain including
what functions are referenced and what data values are used. The
[[QREFELT]] is a "quick elt" function which resolved to a highly
type optimized function call. The [[SPADCALL]] function funcalls the
second argument to [[SPADCALL]] with the first argument to [[SPADCALL]]
effectively giving:
\begin{verbatim}
(funcall (qrefelt $ 21) |c|)
\end{verbatim}
So we modify the [[|CHAR;coerce;$Of;12|]] function to capture the domain
vector thus:
\begin{verbatim}
(DEFUN |CHAR;coerce;$Of;12| (|c| $)
(format t "|CHAR;coerce;$Of;12| called")
(setq tpd1 $)
(ELT (QREFELT $ 10) (+ (QREFELT $ 11) (SPADCALL |c| (QREFELT $ 21)))))
\end{verbatim}
Again we rerun the failing function and now [[tpd1]] contains the
domain vector for the domain [[CHAR]]:
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}