Sie sind auf Seite 1von 52

Hannes Goldynia

St. Martlner Str.45


9500 Villach

. "
mullSP /muSTAR-80 tm
\

Artificiallntellioence
..,
Development System
Re1ercnce Manual
COpyright Notice
Copyright (0. 1980 by The Sok Warehouse. All Rights Reserved Worldwide. No pan of this m.anual rT
~p(oduced. transmined, transaibed, stored in ~ retrieval system. or translated into iny human or Corr
I.anguage. in any form or by any means, eleCtronic, mechanical, magnetic. optical. chemical man\..
otherwise. without the express wrinenpcrmission of The Soft Warehouse. P.O. Box "'74. Hon
Hawaii 96828. U.S.A.

"l-'
~lO

Discbimer
The Soh Warehouse makes no representations or warranties with-respect to the contents hereof and specific
disd.ims any implied warranties of merchantability or fitness for any paniculv purpose. funner,
August 1980 Soft Warehouse reserves the right to revise this publication and to make changes from time to time in
content hereof without obligation of The Soft Warehouse to notify any person or organization of SI
revis;on or changes.

muUSP/muSTAft-80 i~ distributed exclusively by


Miaosoft
10800N.£. Eighrh.S\J'tt~ 819.
::' Copyright (C) • l~O ~ Bellevue, \VA 98004
Th~ Soit W .IrehClus~ tt(l
All RiKhts R~~nt.~~ \\'4lfldwide~) '../ 8701- :'00-02
R.'nri""·ft ~-f:~l , ••·,,,,i··..... ,
L \ :.-~ I s, T . ~ 11_
Preface

The LISP computer language is based on a paper by John McCart.by


A Brief History of muLISP [1960] entitled ~.J.Csive Functicns of Symbolic Expressioos and ~eir
Computation by Machine-. Since its first implementation at
the Massacl"lusetts Institute of Tec."malO3Y in the early 1960's, LLSP b..:lS
muLISP-80 represents the culmination of 4 years of effort into remained the ~machine languase ft of ~~e AI (Artificial Intellisence)
designing a general purpose LISP system. It was developed almost 'n1e language and its marrt derivatives ccnti..~e to monq;.cl.i=e
CCl't.Qunity.
entirely on microcanputers for m.ic:rcx:ant:Uters. 1'he original interpret.er all serious work in such diverse fields as robotics, nat.Utal langl:ase
was completed in 1977 by Albert O. Rich using LISP 1.5 as a guide. It translation, theorem proving, medical diagnosis, game playing, and
was int:.e.nCed solely for use in mec..~caltheorem PCCN"ing, s-pecifically pro;ram verificatiO'l. LISP is the language of choice for such a~...emptS
for the propositional and predicate calculus of formal logic. This at mec.~cal intelligence for the fallON ing reasatS:
system, now called muLISP-77, worked quite well for this purpose,
althCl.lgh someJhat slcwly. 1. LISP is an applicative, recursive language which
makes it an ideal formalism for describing complex
'Ibrough the foresight of David R. Stoutemyer, it became ap-~rent mathematical cooceptS..
that the potential uses for a microcanputer LISP were t:emendOJS. In
plrtiCJ.1a.r, the possibl i ty of imp! enent..i.D3 f or the first time a syrr.bol ic 2. The principal data structures in LISP are binary
mat."1enatics system on a microcanputer was set as a gcaL Influe..".ced by trees. SUch abstract cbject.s can be made isancrphic to (Le-
t..'1e irrlaluable suggestiQ'lS of Martin Griss and Peter Deutsch., joint work a one-to-one model of) the actual data in mos~ AI problems.
by Rich and Stcutemyer yielded a greatly enhanced and robust LIS? Once this is accomplished, the properties of ~~e original
system. It included infinite precisim arithmetic, streamed ask file pr cbl em can be investigated by t=erl crmiD] transf ermati Q'1S on
I/O, ar..d a paJerful functioo bcdy e'laluatiOO mec.bani.sm. '.!his ptod1c~ the LISP data struet1lres.
vas released in June of 1979 as JDuLISP-79 by'l'he 50ft Warehouse, a
par+"-..nership set up by StOJtemye.r and Rich to facilitate the widespread 3~ When a computer is programmed to simulate
distrituticn of the sofblare. intelligence, it must be able to respond to queries of
arbi t.I a.r:y difficul t::y. The static storage allccatioo sc...~emes
The success of muLISP-79 and its companion product the of ca'rJ'entioo.al programming languages makes it very diffiOJl t
IUlSDlP/mu..M.1aB-79 CD Symbolic Math system encouraged further work on to dea.: with such ~ ended prcblems. 'lbese diffioJ.lties are
1m'proving the systems.. The need for greater code densi ty and faster allevi.41ted in LIS? by dynamic allocatioo and recycling of data
leading capabllit:::l resulted in the addition of a pseudo-code canpiler storage re.soo.rces by means of autanatic garbage collecticn.
and interpreter for the auLISP-80 system. A major effort went into
making the documention for muLISP-80 of the same high caliber as the 4. A highly interactive environment is essential for
software. '!be clarit¥ arxi completeness of this m.aDJal is we in large
part to the persistence of ~ can B. Rich.
intelligent human-machine canmunicatim. '!he ease with which
LISP functicn definitioos can be regarded as data enccurages
CUrrently work is being done to make muLISP available for other incren\ental system development and makes LISP an ideal
popular micro and minicomputers.. The advent of the 16 bit micro- interactive language.
prccessors will make possible the greatly impr01ed perfcrmanceand data
space sizes r«iuired to satisfy the needs of ever larger AI research
'!be Cevelc:pnent aOO distrituticn of muLISP-79 by !be SCF1' WAR.EE:OSE
efforts. We i.ntended to fulfill those needs.
helped to make LISP available to th.e rapidly grOJing communit:'J of
August 2, lSSO micrcx:c:np.lter users. '!his was the first efficientr -Ptcd1etioo· versicn
of LISP for such computers and is bein~ used in a wide variety of
. ~icaticns. ,
The challenge to meet the ever increasing memory and speed
requirenents of most AI software systems inspired the development of
muLISP-80. An increase in code densit::y by a factor of three and a 20\
increase in exeOJticn speed has been achieved by means of a pseudo-cooe
compiler and interpreter. Since compilation and de-compilaticn occ..:r
automatically, the process is invisible to the user. Thus, t.~e
interactive r.ature of muLISP, so essential fer mast AI aWlicati~.s, is
• not sacrificed in t..'1e interest of efficiency. Finally, t:.'"le addi. tion of
the mUS'r.J\R-80 AI Development System to muLISP ra.mded out the package
vit."'l a resident display-oriented editor and deb..lgging facilities.

iii

iv
--------'---_...
...,..... ...... --- ~ . "'"'lI!!'" _ .........
N.
o. Printer Functions and Control Variables• • • • • • • • •
Evaluation Functions • • • • • • • • • • • • • • • • • • V-2.1
P. V-25
Q. Me:Dory Management Functions ••••••••••••••
'fable of Contents
Environment Functions _ • • •
..... V-31
V-32

Title Paoe • • •
.. .... .. i
VI.
A.
~ DIJSrAR AIDS
Main Menu Coaxnands
Copyright Notice 1i
... .
........ VI-3
1. e:titor Facilities ••
Preface • • • • iii VI-2
2. Debugging Facilities • • • • • • •
A Brief ei.story of muL.I.SP
Table of COntents
iv
v Disk ~O Facilities
3.
B. Text Editing
••••••••••••••••
VI-4
1.
2.
CUrsor Control •
Display Control . . . . . .
. . . . . . .. .. .. .. . . VI-5

. . . . . . . . . . . . . . VI-a
I. .AD Int.rcrlJct.ia1 to D.1LISP-8O 3. Entering Text VI-6
A. Major Features • • • • • 1-1 4. Deleting Text VI-7
B.
C.
'!he ~.aster Diskette
The Basic Interac+"-lQ'1 Cycle
I-2
1-3
5. F irrlingNames
6 • Ex.i ting Editor • • • • • . .. .. . . . .
. VI-a
D.
E.
'!he Exec..1tive Driver Loop
U11L.ISP Ptog ran:m.i.ng • • • • • • •
I-3
I-4 c.
7• CClIma.OO SUntnary
Custanizing II11STJ\R
Table . . . . . . . . ... VI-a VI-9
F.
G.
Interrupting Program Execution • •
Error oiat;nostics • • • • • • •
I-6
I-7
1.
2.
Console CJ.stomi.zation
The lIIJSTAR Executive • • • • • • •
.... VI-IO
o
B. Eav'ironment SYS Files 1-7 3. Text Data Structure . VI-ll
... Text Primitivies • • • • • • • • • • .. _ • • • • • • VI-ll
VI-12
IL Primitive Data St:xuctw:es
.A.. Names II-l
.B.
c.
N.mCers
~ . .. . II-2
II-3 Appendices

III. Kemoxy Management. c.


A.
B.
Backl..:S-Naur Fom • • • • • • • • • • • • •
Bow to Copy the Master Diskette •• • • • •
.. .. . . A-l
A-2
ImpleDffiting Machine Language SUbroutines • • •
A. Initial Data Space Partiticn • • • • • • • III-l D. LISP Bibliography • • • • • • • • • • • • • A-4
. B. GaJ:bage COllection • • • • • • • • • • llI-l E. A-5
III-2 -F.
Function Index • • • • • • • • • • • • •
C. Reallocation of Data Space Boundaries Concept: I.rxiex .... _ _ • • • A-6
D. Insufficient Me:nory Trap • • • • • • • • • • • III-2 A-9

IV. 'rbe JIU-LI.SP Meta-] ~ e


A. Heta-syntax • • • • •
B. ·Me~tics • • • •
IV-l
IV-l
o
v. Prlmitively Defined FUrx:tioos
A.. 5el~~r Functioos •• V-l
B. COnstructor Functions V-3
c. Modifier Functicns • V-4
D. Recognizer Functions V-5
E. ~ator Func-~cns • • ..,e • V-o
F. Log"ieal Functions . v-a
G. Assignment Functions V-9
B. Prope.rt:/ ~..J.ons • V-ll
I. Flag Func+'--icns • • • V-12
J. Def ini tion Functions V-D
It. SUb-atemic Functions • • • • • • • • V-14
L. ~erical Functions • • • • • • • • • • e ••• V-16
K. Reader Funct:icns and Control Variables V-l7
vi ~)

v
Section I: An Int~oduction to muLISP-80
')" 7. In addition to muLISP's interactive environment,
program debugging is facilitated by a resident display
Congratulations on your purchase of the muLISP-80 Artificial oriented editor and a trace package. (see section VII)
Intelligence Development Syste.t1 (mu.LlSP-80 AIDS). This system is a
revolutiof'..ary and sophisticated soft-flare package for m.icrocomFu~ers. It 8. muLISP is fully integrated into Digital Research's
has been designed to ce capable of S'l..~rting a 'Wide range of serious AI cp/Mtm Oisk operating system and such upward comp~tible
research efforts. Some degree of study and patience is required to successors as Cromemco's ax:s tm , and IMSt\I's l:MIX)Stm.
properly use muLISP-80 as a development tool for the 'large soft·"'are
systems required for such aA?lications. 9. muLISP requires only 9K bytes of machine code
storage, leaving the remainder of the compute;'s memory
This section of the muLISP-60 AIDS Reference Manual provides the available for &ta. stt:uctures. A m..ini.mum system run inwill
m.ini.~uminfocnation necessarJ to load and use the syste...'l\,. The re.'Uair..c~ as little as 20K bytes of comp.lte.r memory.
of the mar.ual provides a detailed explanation of muL.ISP di:lta str~....ure.s,
memory management, and primitively defined functions. ~~ery at~~pt. r..as 10. Extremely fast program execution speeds have been
been made to make the manual as clear and precise as l=Ossible: howeve:-, achieved through the use of such techniques as shallow
it is Dot a tutorial en t.he LISP programming language. The best way to variable bi..r¥iin3, address typed data sttuetures, arx1 a closed
learn cuLISP is by exploratory use of the system in parallel with so.:dy pointe.t universe. (see section II)
of this manual. If this reveals an insufficient knowledge of LISP on ;~
the part of the user, several good references are given in tb.e 1.1. E\1IlCtioo definiticns are automatically compiled intO
bibliography at the end of this mat"IJal. distilled code or D-COde when they are defined. The inverse
process of de-<:ompiling occurs automatically when a definitien
is retrieved. This compilation results in a threefold
A. Kajor Features increase in code density over storage as a linked list and
about a 20\ impl:ClVement in execution speed. (See section v-J)
1. A total of 83 LISP ftmctions are defined in machine
l.anguage for maximum, efficiency. These functions provide an 12. N.lmercus I/O control variables have been in:luded to
array of data st.rueture primitives incl~ a full complement handle such issues as upper/lower case conversion, console
of selectors, constructors, modifiers, re<:09ni%ers and edit mode, and the printin<; of quoted strings. (See section
canparators. (see secticn V-A,B,C,D,E) v-H,N)
2. Infinite precision integer arithmetic, expressed in 13. A means is provided to conveniently link to user-
any desired radix base from 2 through 36, is supported by· a defined machine language subrcuti.neS. (see section v-\J)
c:cmplete set of numerical primitives- (see section V-L)
3. A two-pass compacting garbage collector performs B. ~he KaSter Diskette
automatic, dynamic memory management on aJ.l data spaces.
'l1le muLISi?-80 system is distributed for mi.crocomPJters as a set of )
A garbage collection typically requires less than half a
secood to canplete. (see section III-B) , djsk files en CP/K focnatted floppy di.skettes. 'The exeoJtable ~
file MULLSP.C)M is an object code version of the rnuLISP interpret.er and
4. Dynamic reallocati<n of data space boundaries occurs compiler. Also included on the diskette are the following muLISP
automatically to most efficiently use all available memory sys ani library files:
resources. (see sectim III-C)
MDSmR. SYS 'ttle tIUSrl\R AI Development System
s. Program control constructs incJ.JJde an exte.OOed CCNJ, tJTll,IT"i.LIB
TRAC£,.LIB
An assortment of utility funCtions
A funetioo-ttace debugging package
a multiple exit IDJP, ar.d a powerful function body evaluation
mec..'1anism. 'lbese features [:er:nit programs to be written in an M£r1\.'1~.Lm A sample program for the MasterMind game
elegant, p.1re LISP style while still allowing the efficiency l\NI.M.AL..LIB A sample program for t.~e Animal game
of iteration when it is awlicable. (see section V-{]) IX::CTOR.LIB An impl~entation of t..~ DoCtor program

6. I.AMEOA defined functions can be made either call-by- As soon as possible after receipt of your muLISP-BO diskette,
value (CBV) or call-by-name (CBN). In aeXtition func-~ons can make a copy of ~~e ~ASter on a blank diskette for use as a Yorking copy.
be defined as being either spread or no-spread. (See ~..ion An a~ to ~'Us roanual provides more informaticn on how this an be
IV-B) accomplished. Once copied, the master diskette should be kept in a
safe, cool place to be used only in emergencies. ~
~
$ IXX;
:; C. The Basic Interaction Cycle tx:G
(
~. the master d.iskette is safely backed up, it is a simple matter $ (PLUS S -2)
' .....

to initi.!te execution of muLISP. First bring up the computer's disk 3


operating system in the normal manner. Next, if necessary, switch to
the drive with the copy of the muLISP-SO diskette. Then enter t.he $ (10 OAL I:X:X; CA1')
followi.ng operati.ng system. command, te.c::ninated by a carriage retum: NIL
A>MtJLISP
$ (MEMBm rxx; (Q tx:1.IE (CAT <nl IXX.i PIG»)
T
After a few seconds of load .time, the system should respond with
a lcgca me.ssage of the following focn:
Often it is advantageous to define an executive driver loop
(8080 Versioo Itm/OiJ!yy)
Dl.IL.ISP-80
especially suited for a particUlar application. This can be
Copyright (c) 1.980 tthe s::FT WAREHaJSE accanplished simply by redefining the funeticn CRlVER. For example, an
eval-quote-LISP driver is given in t..'1e library file O'I'ILITY.LIB. If an
S error or interrupt occurs, program ,control will return to the user
defined driver rather than the perhaps inappropriate default driver
where aR?rcpriate numbers ~ for the verSiCX1 mooth, day, and year. locp.
This version date should be included in all inquiries concerning the
system. t-latu:ea.lly, the ZOO ve.rsicn of mur..I..SP-BO. will have ·Zoo- instead
of -8080· in the logon message. E. muLISP P~ogrammin9 o
m.uLISP prompts the user witb a dollaJ:: sign to indicate re.ad.iness to The follaling muLISP dialogue illustrates how a'LAMBDA defined
. accept chataeter i.npJt from the console. After a complete expression functial can be defined and then used:
followed by a ea.triage return is typed by the user, muLI.SP evaluates the
expression, and prints the resulting value beginning on a new line. . $ (rom (OtXm: F~) (QtXm: (LA'-!8OA n~
'nti.s interaction cycle is repeated indefinitelyunt:il a c.mr.rc is typed, (CCND
retw:ning control to tbe disk opera.tin.c; system. ( (Z fR)p N) 1)
(T (TlMES N (F~ (DIFmtm::E N 1»» ) »)
Since m.uLISP uses the l..iDe editi.ng rootines of the host ccmpJter's F1Cl.'tlUN..
operating system, all the appliCable features of that system are
inherited by muLISP. _ is usually accomplished by typing a $ (F1ClIJR.I}.L 5)
~ a mlBout., or a DELete. some· ~ ecbo t:be deleted character: 120 "-
others erase the charact:er from the screen and backspace the cursor.
Entire lines can be deleted or flusbed by typing a. CT.RL-o or a CT.RL-X. 'nUs definitiQ'1 of the factorial functi<X1 is defined in the style
By typing a CT.RL-P, all subsequent muLISP console output will also be of the original LISP as described in MCCarthy's Ll.S.E. L5. P:oorammer'~
sent to the system's pri.rtte;.r. ~ [1.962]. Altboogh it does not fully utilize the catabilities of
In general aUy the current line can be edited. There is no wa:f to
codify a lir..e of i.npJt once a carriage retw:n has been typed. However a
muL.IS?, it is a perfectly acceptable definitioo.

StIJdy of this manual and the muLISP library files will reveal that
o
nmaway program can be interrupted. as described in the next secticn. muLIS?-80 incorporates numerous upward compatible extensions of LISP
1.5. For the most part these extensions consist of defining useful,
well-defir::edresults for which t..~e original LISP is noocanmittaL They
D. The Executive Driver Loop significantly increase readability and execution speed, while
substantially decreasing the storage requirements for function
The defa:Jlt muLISP driver loop is an eval-LISP executive. First definitims. The falla.r ing are a few of the significant e.xtensicns:
the prompt string, .$ 11;, is displayed, indicat:.i.ng the system is waiting
for console i.np.lt.. 'lbe user can then ent.er an expression ter:ninated by 1. As a name is read or generated by muLISP, its value is
a carriage return. Multi-line expressions can be entered since an automatically set to itself. This self-referencing of nef.
expression is not considered complete until all parentheses are
balar;:ed. CD:e entered, an expression is read usi.ng the func'ticn RE.t\O,
naI:1es is called auto-quoting. It reduces t:.~e need fort using
the Qt.:OrE functi CX'1 when the f)J AL-f.,ISP e.xeo..t tive d: i ver locp is
evaluated using t.~e function FYAI..# ard then t."1e result is print.ed using being used for i.n{;u t.
the function PRINT. The' following is a sample muLISP dialogue
demoostrating the basic driver loop:

to.
!-4
I-)
{rom FlC1'CRL'L (Qt'.X:YIE (LAl-18OA (N M)
(SE'lQ M 1)
. (LOOP
«Zm:>P N) M)
2. The CONO function has been generalized so' all t.'1e (SE'lQ M (TIMES M N»
) expressions fallow ing t.'le predicate are evaluated in turn. (SE'lQ N (DIFFE:RnJCE N 1» ) »)
The value returned by this extended COND is the value of the
last expression. '!be f i.e st is a caNenti anal non-reo.u:sive definition. 'the seccn1
is the 8:luivalent muLISP-SQ definiti~ also non-reoJ.rsive.. '!be reader
3. The evaluation algorit.t.un for a ~unction body or can decide for him/her self which definition is m.ore elegant and
lambda e.xpressicn includes an implied cam. 'I:U.s obviates t.'1e structured. It is interesting to note that the muLISl? definition
need for explicit use of COND within function definitions. r8:1Uires onli 29 nodes 1 whereas, the CQ1\Tenticna.l version r£quires 38.
P

For example, compare the follO.-ling definition of FACTORIAL '!his is not an insignificant ratio for a LISP system running in a very
vitb that given abo.re: limited ac3dress space.
(PlTlD F K::!OR.IJ'L (QtX:m: (IAJtBOA (N)
, «ZEroP N) 1) F. Interrupting Program Execution
(T'lMFS N (FPC'1UR..IAL (D~ N 1») »)
At any time during the execution of a program, a user initiated
software interrupt will halt pco;ram exeQltiCXl. '!his may be necessary ."J
Wit."l the principal exception of the PRCG prbgram control coostruc~, to st~ a "runawaY' ex nal-te.r:minating program and return control t.o the
the original LISP was an exemplary at=9licative and structured l~gua<;e ca'lSale. M interrupt is initiated by depressing either the ~pe ke:-j
lCX19 before these adjectiv~ became pcpJlar. muLISP has t:Jo feat:.lres ex AL'Dnode key. '!he follO.ting optiCXlS available m.essage will. then be
which dispose of Mrf need for sucn unst.rUC't11ted ca1trol features: d.isplayed on the coosole:
1. 'rhe pGlerful multiple-exit LCOP funeticn permits the ***nm:xt<LU?1': TO Conti.Iue tYPe: RET:
pro;ramming of non-recw:sive loops. 'lbis is ac."lieved witbOJt Executive: ES:, H.:rJ Rest:art::R[Il, DEL; Syst:eD: cmIrC?
the use of the totally unstroeturecl GO feature.
'lhe user may then choose ale of ·tbe follOtling optioos by typing the
2. Arguments in a function's formal argument list that a;:propriate optioo character:
are in excess of the actUal num.ber of arguments used in a call
to the function are simply bound to NIL. 'ttlese excess 1. ~e Continue option causes I program e.xeC1.:1tion to
arguments are available for use as loc:.al variables wit..'ti.n the continue from the point of the interrupt.. This option is
function: hence PROG is not needed to estaDlish such. loc:a.l selected by depressing the R.E1\lrn key.
variables •
2. The executive option returns control to the current
executive driver loop. All variable bindings, function
For these rea.saJ.S muLISP-80 has no primitively defined ppa:;, CO, or definitioos, ex prq:aert:{ values are preserv'"ed. '!his option is
RE:I.Um CalStruets. Instead of havin<j sucb explicit control ccr..struets, selected by depressing either the ESCape oc PL'Dnode key. For (.J
pro;ram CQltral within a muLXSP funeticn body is guided primarily by the terminals 'W i t...'1 nei ther of these keys, typing a CTRL-( (i.e.
structure of t.be linked list representing the function's detinition. typing a left bracket while halding dain the cootrol k.ey) is
Implicit program control results in function definitions whose EqUivalent to ESCape.
appearances are uncluttered and whose meanings are more transpa:ent..
See section v-a for a detailed explanation of me muLIS:i? evaluat.ion 3. '!he Resta.r:t option restarts muLISP fran scratch arrl
mechanism. destroys all variable bindings, ncn-primitive functions, and
pr~t.y values. '!his optioo is selected by depressing either
As an example of hew to avoid the use of these constructs and the DELete or ROBout key. Typing a CTRL-a is equivalent to
thereby write more struct.ured LISP programs, consider t..."le follOtfl1ing depressing th,e DELete key.
OefinitialS of the FPClDRIAL functicn:
4. The System option ter-:ninates muLISP and ret.urns
(mID FiCIORI.AL {QrorE (LAMBDA (N) cootral to the disk q:aerating system. '.this option is selected
(P~ (Ml by typing cmL-<:'
(SE'lQ M 1)
A (CXlD
({ZERJP N) (R.E'lURN M»)
(SE'.IQ M (TIl1fS M N)
(SE'.IQ N (OIFFER.D.'CE N1» I~
.~
(GJ A) ) »))
A SYS fil.e can be useful in a variety of ways. For instance, an
interactive session can be continued at a later time, intermediate
resul ts of a session can be backed up as insurance against computer
muLLSP out;ut to t.."'le console can be interrupted and t...~en res-~t.ed
failure, or a set of function definitiCXlS devel~ interactively can be
) using CTRL-S as a toggle. This output pause is useful to petmit reading preserved. Finally, program development is usually done by creating
of t.'ie text prior to its bein9 scrolled off the screen. mliLISP scuree files and reading them in using the RDS canmand. B~etler,
alee the program has been perfected, reading it in each time can be
tedious especially for an end-user. If a SYS file has been generated
G. Error Diagnostics containing the source, the application program can be loaded bot."l
There is only one 'situation in muLISP-80 for which there is no qUickly and CaNeniently by the end;-user•.
satisfactor:.y recovery other than program te.cnination and an error trap.
~he exhaustion of all available storage in the four da'ca spaces will
result in an error trap. See section III-D for a discussion of the trap
and the options then available to the user.
A less serious problem will cause" a wa.rn.ing message to be displayed
(Xlthe ccnsole.' The primitive function in which the error OCOJrs will
return a, value of NIL. It is then,' the responsibility of t...1.e user (
program to recognize the error and take the appropriat.e action. The
following are the t.."1ree possible wa.cning messages. Their causes are
fully described in t.~ indicated sec:tia1S of this manual:

ZEro Divide Error Section V-L


En:3.-of-File Read SectiCX1 V-M
No Disk Space Section v-N

B. Environment SYS Piles


The muLISP function SAVE is used to save the current environment
for retrieval at a later time. Tbe environment consists of all the
currently active muLISP data structures, ~ atom values, propercy
values, and function definitions. The environment is saved as a~disk.
file of type SiS. For.instance, the followiD:J command wUl gene.rate a
SYS file named WBALE.SiS on the a:Ltrent drive:
/
$ (SAVE (~ WHM..E) \..
This environment can be restored at: any later time by using the
LOAD function. If the fUe WBALE.SYS is now on drive a, the following
muLI.SP commatXi wll! load t:he SYS file saved above:

$ (LOAD (~W1!ALE) (~B»

Alternatively, the followiD:J operating system command can be used


to load the SYS file WBALE.SYS from drive B after loading muLISP:

A>f1I.ILISP B:WBALE.SIS

Eit."ler of the above methods for loading a SiS file will restore the
environment exactly as it was at the time of the save.. When a SiS file
is loaded, the various data spaces are re-allocated according to the
comp,lter's current memory si%e.. This means that tr..e current. me-mory size
does llQ..t. necessarily have to be the same as when the SYS file was
created. 1-8

!-7
3. A name's function cell contains a pointer to the r
o.trrent definitioo of t!1e name. '!his function definiticn can \-
either be a machine coded ra.ttine or the IM:ode representaticn
of a' LAMBDA expressioo. When a function at=Plication is to be
) SectioQ II: Primitive Data Structures made, the function cell is used by the muLISP evaluation
mechani..sm to locate the name's definition. h::cess to the cell
1s limited to the function definition primitives, which are
muLISP has three distinct ~s of primitive building blocks, used to retrieve and modify functioo definitions. When a name
collectively called data objects. A data object is either a muLIS? is created, its funeticn cell points to .m undefined functioo.
name, number, oc node. Osinqt:be recc;sni..zer functions, the t.yI:e of aIrf trap.
data object can be determined. All the data cbjects of a given type
eatSist of a fixed number of pointer cells. A pointer cell can point 0= 4. A name's print name cell contains a pointer to the
refer to other data cbjects or to special l:UI1?OSe data structures. Thus string of ASCII characters used to print the name. Access to
the set of data cbjects can be envisioned as an interconnected net:Ncrk this cell is restricted to t.~e I/O and sub-atcmic functicns.
of pointers called a pointer universe. When a print'name string is read in or generated by the
system, a check is first made to see if a name already exists
It is impc;rtant to note that all t.."1ree types of Ca ta cbj ects bave a with t:...~t print name. If so, .~e existing name is used. If
car eel.l and a cdr cell. More01er, in muLISP the car and cdr cells are not, another 'name is created using the new- print name. Once
rest:.rictt.."d to fJOint ally to ot:.l-ter d:>jects w it.~ the point& uni"Je.rse. created, .a name's print name string cannot be modified.
1bus by follo.ling a'lly car and cdr cell pointers, there is no danger of
wandering outside this closed universe. The advantage of this closed
pointer universe is a simpler and more logical muLISP evaluati~
o
mecbanism. For instance, it eliulinates the time required for Ca1.St:ant
• i I
~ checking on t:.be part of the primitive LISP functicns. B. :bItlers Nt.mber I Sign I vector
I I I •
I I t I I A number is a recogni:zable data ct>ject coosisting of three pointer
A. NaDes I Value I Property I FUncticn 1 Pname cells. Numbers are ..D.Qt uniquely stored in the sense that equiValent
• I I I t· . number veCl:ors can occur in the system.. The use made of each of the
three cells is as follGls: .
A name is a recognizable data object consistinq of four pointer
c:e.Us. Names are uniquely stored in the sense that no two names in t.~e 1. ~e car or value cell of a number contains a.pointer
system can have identical print-names. 'l11e use made of each of the four to the number itself. 'Ihus numbers do not have to be qu~
c:e.Us is as follcws: . since they evaluate to themselves. Naturally the cootents of
this cell can be changed by using an assignment function;
1. '!'be car or value cel~ contains a pointer to the however, there is no reason to do so and it is not a
current value of the name as recognized by the evaluation reccmmended t.hi..ng to' do. ,-
functions. When a name is created, its value cell is
initialized to point back to the name itself. 'lbis autanatic
self-referencing of ~ name, called auto-quoting, often
2. '!be cdr cr sign cell of a rJJmber points to NlL if the
number is non-negative: otherwise, it points to 'nUJE. The
o
eliminates the need for explicitly usi..ng the QOOTE function in value of this cell is established when a ~ is created.
functicn aefinitions. The assignment functions are used to
change' the value cell of a name. The value cells of a 3. The number vector cell contains a pointer to the
function's formal arguments are tem~rarily reassigned whe.rt bir.ary number vector which establishes the number's numerical
the function is ·called, and then restored to their original value. The number vector itself consists of a single-byte
value when the funeticn is exited. byte counter follOtied by the requisite number of bytes
required to express the number in binary. The size of the
2. A name's o:1r or property list cell cootains a tx>inter byte COJrlter limits the magnitude of numbe.rs to 256"'254-1 or
to the property list of the name. This list is used and at=Proximately lOA 611.
modified primarily by the property list and flag functions.
Flags on a property list can be distinguished by t.'1eir being
atomic elements of the list (i.e. na~es or nUI:1bers). In
contrast, prope.rties are non-atomic elements of the list.
(i.e. nodes). The car of a prop.erty element points to t.he
property's indicator and t.'1e cd: points to the propert.y's .
val~e. When a name is creat.ed, its property list is set to
NIL,' indicating that no flags or 'Properties are present:. 1I-2 ')
Section III: Kemory Management
I
I I I
car Cdr Dynamic, invisible memory 'management gives LISP much of its
C. NOOes inherent power. This frees the programmer from concerns about.
allocating sufficient memory for a given problem. Such allocation
Bi.nary trees are the primary data cejects in muLISP. Internally a
before run-time is difficult, if not impossible, for most A!
applications since the problems are generally not of a predete.cmined
binary tree is implemented as a network of cell pairs called nodes. size. Memory management is accanplished in three ~s by muLISP-80.
Each node consist of a car cell and a cdr cell. A:5 mentioned earlier,
the node's· cells may a'1ly point to other txnafide muLISP data cbjec--s:
a name, a numbe£, or a ncde.. A. I.nitia.l Data Space Partition
t

'lraditicnllly nodes have been called dotted pairs in deference to


the dot notation used to represent them in print. The expression turing the initialization phase of muLISP, the amOWlt of memory
(X • Y) represents a node whose car cell points to the object X, and
available to the system is canputed. The memory is then parti tioned
whose cdr cell points to the object Y. The dot notation is perfectly into four distinct data spaces based on the ratios given in the
follcwing table:
eatable ~ expressin; arrJ LISP data structure..
It is often more convenient to think of data as a linked list of ~ ~ CCJ1tents
elements, rather than as a deeply nested binary tree structure. The
structure represented by the list (Xl X2 X3 ••• Xn) can be expressed 4:32 At:an space Name and nt.mber pointer cells
3:32 Vector space Print-name strings and nuni;:)er vectors
us.i.n; dot notaticn as 23:32 Pointer space D-code and ncxies
(Xl • (X2 • CX) • (.. • • (xn • NIL) ••• »». 2:32 Stack space System cootrol/value stac:X

To create data objects required for a running program, space is


'rhus a list consists of ~ ~.aain of nodes linked through their cdr taken from one of the above spaces'. Space for a new namels or a. new
cells. 'lhe name NIL is used in the last cdr cell to terminate tP.e list:. . number's pointer cells is taken fran the atom space. At. the same time
NIL is also used to denote the null or empty list.· 'IhuS the expression space for the associated print-name string or number vector is taken
() -'II ill be read as NIL by the function READ and printed as NIL by the
fra:1 the vector space. 'the pointer spa.c~ which. is by far the la.rges~
functiQ'lS PRINl. and ~ prO/ides storage for both D-c00e and nodes. 'nle canbined CCX'ltral staCk
'rbe function READ will accept both the dot notation and the list and value stack is located in the stack space. The above ratios
notatiCX1 fer: expre.ssing data structures. EGle'ler,· the functialS PRINl approximate the relative use made of the spaces by most application
arxi PRINT will use the list notati<n to the max;mum extent possible when prograns.
printin<; struCtures.
B. Garbage Collection
\
'!be nature of stack operati<X1S makes management of the stack S""'~ce
auta:atic and continuous. fiG/ever, management of the re:naini..ng three
spaces r~.res explicit rec"fcli.ng of data cbjects \{hic.~ are no'lcnger
neeCed.. New data cbjects are ccr.stantly c::eated during t.'1e e.xecJticn of
a LISP pro;ra:n, while others are implicitly discarded when they are no
100ger referenced 't:Jy active structures. . When the creaticn process uses
up all available resources 'W ithin a space, a garbage collection is
performed. The storage space vacated by discarded data structures is \I
then reclaimed, so the process may centime.
\I
In muLISP-80 the exhaustion of resources in either the atom,
vector, or noee spaces will cause a callecticn to cccur. The fiIst pass
,,
j
of the collectioo coosists of marking those data structures accessible
fran t.'e value and prc:;;:'Ert"1 list cells of all syste!Il r.ames and frO':\ t..~e
variable stack. During the second pass, the marked or active data
objects are ccm.pacted into one end of t."leir respective data spaces.
This leaves the remainder of the spa.ces available far new d:>jects.

TT-"t
IV. Tbe muLISP Meta-language

The applicative nature of the language makes LISP an ideal


Although garbage collection is automatic, it is not entirely formalism or meta-lanquage for the precise spec.ificaticn of both natural
invisible to the user since it periodically causes a pause in the and computer languages. In fact LISP can be used as its own meca-
execution of a program. Less than half a second is required for the langua<;e! The use of LISP in this way dates back to John MCCarthy's
collection process in a 4SIt byte muLISP-80 system using a 4HH% clock.. original investigations into the language, and the practice has
The time varies linearly with the computer's memory size and clock continued t.o the present. When LISP is used as a meta-language, it is
speed. Normally this is of no concern to the applicati,on level custanarily written in a more natltCal, high-level syntax called meta-
programmer: hc:wever, it sh01ld be coosidered in the design of real time LISP. While borrOJ inq heavily from the concepts discussed in Allen's
systems. AAatorny ~ L.IS2. [19781, the muLISP meta-language has been syntactically
enhanced to more clearly reflect the extended evaluaticn capabilities of
the underlying muLISP.
c. Reallocation of Data Space BOQDdaries
If after a 9arb~ge collection there is insufficient free storage A. Meta-syntax
within a data space to continue a process, the partitions of all the
$faces are r~ocated to give more memor;y "to the exhausted space.. 'nlus '!be follQiing table defines the syntax of the muLISP meta-language
muLISP can respond to changing demands placed on the various data using BaCKus-Naur Form (BNF) first described in the .ALGOL .n.o. ~
S'p'.ces by differing at:¢icaticn programs. [19631 and summarized in an a ~ to this manual.

<defini ticn> ::- <ftype> <identifier> [crar-list>l :- <1XXtt>,


D. Insufficient Kemory ~ap
o <ftype>
<var-list >
::- ON 1 caN
::~ <variable>, ••• , <variable>
Normally, automatically invoked garbage ecUecticns and dynamic <body> : :-<clause> , ••• I <clause>
reall~tion of data spaces w Ul provide ~uffic1ent storage in each <clause> ::- <fom> I <ca1ditiooal>
space to cCX1tinuo.JSly satisfy the de.mands of user pro;rams. HGlfNe::, if <coodi. ti cna.l> ::- <focn> -> <b:xi'i>:
the me:nory r8:i ui rel:1ents for storing data objects finally exhaust all <for::m> ::- <c:oostant> I <:!/ariable> I ~catioo>
available resources, an insuffi.cient memory trap will occur. Since <assignm.ent.>
every other prcClem that arises in muLISP has a sati.sfaetory rec:o.rerj, <assignnent> : : =- <variable> <- <f aon>
this is the cn1.y sibJatia'l that causes an error trap. '.tt1e trap displlrfS <at;:pl iea.ti en> : :. <identifier> [<f oz::m.>, ••• , <f cxm> 1
the follOJing messa~e on the ccnsale: <variable> ::- <identifier>
<coostant> : :. NlL t 'mOE I. L..Hr1BDA I NrJMBOA I ~>
1U. S[:aceS Exhausted <identifier> is ant muLISP name (s~ sect.ioo II.A.)
Ezeoxtive: ~ JILT; Best:art: 103., IE%'.; Systs: Ct:d-c1 <.nJ.:IIi:er > is aIr;! nuLISP ntJlICer (see Secticn II.B.)

'!'he user may then choose the desired option by typing the This syntax w i l l be used in Section V in the description of the
respective cpticn character. '!he txsz;utive cpticn is the least drastic primitive muLISP functions. Ho.'ever, the formal syntax rules will
since it merely causes control to return to the LISP executive driver occasiooally be supplemented in the interest of imprcving reaCabili t:j.
lc:x::p, withoot c:banqi~ functim definiticns, pr~rty values, etc. 'Ihis For instance, the logical operators -AND- and ·OR", and the numerical
is the most common response to the e.cror trap. The Re:st~rt option operators -+", -..., etc. will be written in their conyentional infix
Cest:'cys all ncn-primitive muLISP func+"'-.iros, prq;erty values, etc. and ~) foens.
restarts muLISP from scratch. Finally, the Svstem. option terminates
muLISP and reb.1rnS central to the parent cpe.rat.in; system. .
B. Keta-se=antics
A phenanencn kncwn as t:b.rashinq occurs when tbe system is forced to
spero an inordirate amomt of time ga.r:bage collectin; a.OO reallcx:at:in; 1. '!be meta-LISP coostant HIL denotes the corresponding
data spaces for a very small net return. The symptom of thrashing is muLIS? name signifying both the empty list, ( ), and the truth
greatly increased execution time for a 9iv-en task. 'Ihis can only be value false. The constant TRUE denotes the muLISP name .I
resolved by increasing the computer's memory size or decreasing the signifying the truth v~ue true..
amaJnt of pro;ra;n
. and data storage rEquirements.
,
2. The function type, <ftype>, indicates t.he 'argument
evaluation scheme used in calls on t.~e function. If a
function is typed as call by value (CBV) I t..'1en the arguments
::'

N-l .

).
III-2
in the function cul are evalu4ted prior to passing them to Section V: PrimitiVely Defined Functions
the functim. On the other hand, call by name (CBN) func--..iQ'lS )
receive. their arguments fran the call w ithoot evaluation.
This section describes in detail all of the functions which have
3. Form evaluaticn is predicated on the partiOllar type ~ implemented as machine language subrcutines. In aCdi tion to the
of form involved. The value of a constant is that constant.. functions actually accessible to the user, several a.ux.iliaz;y functions
The value of a variable is the contents of the value cell of are also defined. These -helper- functions are introduced solely to
the v'ariaole's name. 'the form associated with the right hand simplify and clarify the definitions of tb.e functions directly
side of an assignment is first evaluated and then the value of accessible to the user. Only the accessible funetialS are numbered in
the variable is set to the result:. Function applications ~ defini ticns belOti and indexed in t.'1e a~dix.
proceed as fallOlls:
1he muLISP meta-language described in Secticn N is used as muc."1 as
a. If the function is ON, the arguments are possible to define, the effects and value of each function. Digressicr.s
successively evaluated from left to right., to Engl~~ language text are made a1.ly when an irred.lcible, primitive
CCI'1Cept must be intrex:uced. '!be interpretation which fallOJs many at
b~ The value of the function's formal the definitions is an attempt to give an informal description of what
arguments are replaced by the act.ual arguments, the functim does and Oa.l it is typically used.
evaluated or unevaluated as a~icablet and t.~e old
values are saved. Extra formal arguments which have
no correspondi.ng actual arguments are set to .NIL. A. Selectoe FUnctions
(
c. The function is then applied as described '- Selector functions are used to select a desired sub-tree from a
belGl, and the result saved. given binary tree. This gives a methcrl for extracting information frau
the primary LISP eata structure. OSi.n3 the functioos of this gra.If?, aIr:i
d. .'!he values of formal arguments are restored desired sub-tree or terminal node of a given tree can be reached. The
to their original value. functions CAR and CDR return the car and cdr branch of a tree
respectively. Successive applications· of these two functions is
e. '!he result of the applicatim is returned. sufficient to traverse any tree. As indicated below, the remaining
functicns are merely ca:lt;X)Siticns of CAR and <:DP.. '!hey are defined in
machine language pri.marily for efficiency and cawenience.
4. 'l1le body of a functioo defini tioo or of a cO'ldi,ticna.l
statement coosists of zero or more clauses se~ated by canmas
and terminated-by a semi-eolon. In the application of a 1. CBl CJ\R [Xl :- ,
funetial, its clauses are successively evaluated as follQls; the structure pointed to by the car cell of X;
a. If a clause 1s a form it is erlaluated as ' Interpretatiat: 'Itle correct interpretatioo of the CAR of
described a.bal'e. an expressiQ'l depe.OC.s on whether that expressioo is an
atom or not, and if not whether it is thought of as a
b. If a clause is a cooditicnal, the predicate list or a binary tree. If X is an atom, then CAR (Xl
foem is evaluated. If it evaluates to NIL, () teturns the current value of X. If X' is a list, then
evaluatioo proceeds as normal to the next clause in CAR [Xl returns the first element of that list.
the a.trrent clause list. OthetWise, the body within Finally if X is a bina.ry tree, then CAR [Xl returns
the conditional replaces the original body as the the left or car branch of the tree.
current clause list and the successive clause
evaluatim ccntinues.
2. C8l aJR [Xl :=
'!his process continues until the end of a clause list is reached, the structure pointed to by the cdr cell of x;
at which point the value of the last clause is returned as the value of
the applicatioo. Interpretatim: . Rena.t1<s similar to these aboJ'e apply to
the interpretaticn of the Q.1R of an e.xpressioo.. 'nu.1S
if X is an atom, then CDR (Xl returns the property
list of x.. If X is a lis,t, then CDR (Xl returns the
tail or eve.ryt.."'li.ng but the first elenent of t:.~t: list..
If X is a binary tree, t.~en CDR (Xl ret.urns the right.
ex cdr branch of the tree.
"
N-2 .~) y-l
3. 0Jl CAAR {Xl :_
CAR lCAR (Xl J; B. Constructor Functions

4. CSl CAoR {Xl :_ Constructor functions are used to generate ~~e data structures
CAR (ala eXll: required for the solution of a particular problem. In LISP suc~
structures are realized as a tree or linked list. These can be designed
to closely reflect or mcdel the data structure of virtually aJ:rf prcolem.
Interpreta tiQl:
of a list. ':his fune:t:ic:n returns the lSecond element The principal me:nber of t.."1is group, tbe CONS function, creates a new
node. The storage required for this node is taken from the area of
memory called t."lc Pointer Space. If previOJS CQ1Sing has exhausted the
s. ON CDAR (Xl :_ Pointer Space, a garbage collection is automatically performed to
aa tCAR (Xl J; reclaim the space used by data structures which are no lc:nge.r re::;.uired.
t
1. ~ CONS (X, Yl :-
6. c:sv CXlR [XI :_ creates a node or cell-pair wh~ car cell points to X
and whose cdr cell points to Yi
Q)R {CDR (Xl J;
Interpr~tations: The correct interpretation of CONS
7. 03V CA.AAR (Xl :_ depends on OC'fl the data structure being built is
conceived. When the structure is thought of as a
CM [CAR (CAR (Xl Jl; r list, CONS [X.. Yl returns the list whose first element
\.. is X and w hose tail is Y. If the structure is a
8. CJ!N CAAcR {Xl :_ binary tree it returns the tree whose left or car
branch is X, and whose right or cdr branch is Y. Note
eM (CAR {CJR {Xl J1; that this in no way al tars the stx:uetures X or y..

9• aN CAO.AR 1 :_ ex
2. CBN LIST (Xl, X2, ••• , xn] :-
CAR {~ (OR {XIII; if n=O -> NIL:,
a:NS (E\lAL [XlI, LIST [X2, X3, ••• , Xnll;
10• ON c.AI:DR [Xl :.
Interpretation: This call-by-name function takes an
CM (aJR [CDR [XJ 11 ; arbi trary number of arguments and returns a list of
the elalua ted results.
Interpretation:
Of a list. This funetic:n returns the third element:
3. CIN ~ (X, 'II :-
11. ON CDAAR (Xl :_ KJI:M (Xl -> 'Ii, ,
CDR [CAR (CAR (Xl 11; o RfllEPSE (CDR (Xl, o::NS (CAR [X], Y]];

Interpretation: When given a list x, this function


12. CSCl (DAta (Xl : • returns the elements of X in reverse oreer. Ncrmally
R~ERSE is called with only the one argument.
o:R [CAR [CDR [XII J; However, if a second argument Y is also given the
rerersed list is appenCed to the list Y.
13. ON Q)OM {Xl :_
CJR lCJR (CAR eXJ J 1; 4. ON CBLIST (} :=
a list of the o.lrrenUy active names in t.."le systen;
14. ON <:I.l:DR (Xl :_
Interpretation: The cbje<:t list., or more properly for
Q:1R [COR C<J:lR (XIII; muLIS?, name list is a list of all the names CJrre.'1tly
in t.~ system.. ~e names are listed accordL"'lg to t.~e
order in which they we:e read in or generated: the
most recent names are first and t.."1e primitive names
are last.
V-2
)
V-3
D. Recognizer Functions
) Recogn.izer functiQ'1S ue
used to identify data structures. 'n1ej all
c. Modifier Functions take exactly one argument and return a value of either T or NI:L.
(~
Modifier functions actually redirect pointers in LISP data
structures. '!bus modifier functioos are used primarily for their effect
-'
1. aN NN1E (Xl :-
rather than their returned value. '.they can be used very effectively to if X is a name - ) '.lEJE;,
modify already existing structures, thereby eliminating the need for the NIL;
costly ·coosiz'); to;ether of a whole n&I structure. Since they can easily
produce tn-Ianted side-effects such as circular lists, these functioos Interpretaticn: This funetioo recogni%es names.
shoo.ld only be used by the experienced LISP programmer. For a good
example of their use, see the scurce listing for the m\JSTAA editor.
2. CSl NJMBmP [Xl ::1
if X is an integer -> mJE;,
1. ON RR.M:A (X~ Yl :- N!L;
car cell of X <- Y,
X; Interpretatioo: This functiQ'l recogni:zes nuci:ers.
Interpreta ti01S:
a. Replace the first element of a list X by Y, 3. CSl KIa{ [Xl :-
b. Replace the left element of a dotted-pa.ir X. by Y, NN1E [Xl OR NOMBERP [Xl;
c. Replace the value of an atem X by Y.
0" Interpretatioo.: This funeti<n reccqnizes' ataA1S'~ that is,
~. .
2. C'!!J1 ~ {X, Yl :-
cdr cell of X ( - Y,
X; 4. ON roLL [Xl :-
EO {X, NIL};
Interpretati cx\s:
a. Replace the tail of a list X by Y, Interpretatia1: This funetial recogn1zes the DUll JiSt.
b. Replace the right element of a dotte.d-pair X by Y,
c. Replace the pr~ty list of an atem X by Y.
s. CB1 PLtlSP (X] :-
GaEAmU? (X, O};
3. CSl OCQC [X, Yl :-
~ [Xl -> Y;, Interpretaticn: This funetiQl recogn1zes positive runbers.
Jla.'a1 [CDR [XlI -> RPtJlO) (X, Y];,
OCCN: taR [Xl, Yl,
X: 6. CSt MIN.lSP [X 1 :.
tnterpretatiat: Concatenat;e, withcut CQ'lSiz');, the list Y .J USSP (X, ali
onto the end of the list X. 'I11e resul ting list is the Inte.rpretatioo: 'Ihis funeticn recognize negative numbers.
same as woold have been prcdlced by APreID. HGiever,
OCCNC actually mooifies the fLcst list by redi.recting
the final cdr cell of that list to Point to the secood 7. ON ZER:>P (X] :-
list:.'!bus, if X and Y point to the same list, a . ~ (X, 01;
circular list will result:. If an attempt is then made
to print this list, the printout wi l l continue Interpretatioo: 'ttlis funeticn recogn1zes the zeta.
. indefinitely. I

8. c:IN fJlrn [Xl :-


ZEPDl? [~ER (X, 211; .
Interpretatioo: '!his func:tioo reco;nizes even· numbet's.
of the arguments is not an integer.
)
s. aN LESSP [X, Yl :-
WMBERP (Xl AND NOMBERP cY] -)
X < Yi,
E. Comparator Functions NIL;
CaDparator' funeticns are used to CODlplre data structures. '!hey all Interpretation: A simple less than comparison foc' the
require two arguments and return a value of either 'r or NIL:. numbers X and Y. Note that NIL is returned if either
of the a.x:guments is' not an integer.
1. CIN EO [X, Y] :=
WMBmP (Xl AND NtJMBmP [Y] -> X-Yi, 6. C!!N ClIDERP [X, Y] :-
if X and Y point to the same cbject -> ~;, NJMBffiP (X] AND NUMBmP (Y] - ) USSP (X, Y];,
N:!Li if the address of the cbjectX is less than the
address of the cbject Y -> TRUE;,
Inter?retation: Normally the B:J test is used for the ~;
Equali t:;i canparison of. atans, i.e.. names and I1U111l::)ers.
For objects other than numbers, m tests to see if X rnterpretatim: This func--icn prcviCes a generic ordering
and Y. point to t..~e same location in memory. As fer system names based ·00 their crder of introduction.
described in Secticn II, names are uniquely stored in '!bus if the name X ...,ere introduced before the name '{
ml·LISP. Thus the EQ comparison is an efficient test .. (i.e. X occurs to the right of Y on the object list)
to determine the equality of names. However, since . then ORDERP (X, Yl . w ill return '!ROE; ot..~eN ise it
numbers are not stored uniquely, lO actually cc.mpax:es : returns NII.. When "sPd with na1-atcmic arguments, the
the number vectors of runeric:a.l argum.ents.
n result of this funeticn is essentially meani.ngless.
v
2. CSt £OOAL [X, Y] :-.
roI)M (Xl - ) B:) [X, Yl i ,
A'ICK cY] -> NILi,
BJtW. [CAR [Xl, CJ\R (Y] 1 -)
EQUN:. [CDR {X], c:ra LYl];,
NIL;

Interpretation: The function mOAL is used for the


~ty canparisoo. of two objects, as distinct fran
the identity comtarison prCNiCed by the EO test. 'nle
structures X and '/. are considered equal if they have
isomorphic tree structures w"ith identical atomic
terminal nodes. Or put m.ore crudely, X and Y are
equal if their print-QJts are ;dentical.

3. 031 ~ER [X, Y] :-


J(l'Ct'! [Yl - ) NIL;,
o
~OJ\L [X, eM. [Yll -) 'IRJE;,
MEM3ffi [X, OJR (Yl];

Interpretation: MEMBER (X, Y] will return T if the


expressioo X is EQUAL to anj member of the list I, NIL
otherwise.

4. CSl GREATERP [X, Y] :-


~ERP [Xl AND NtJMB~ (Y] - )
X > Yi,
NIL;
V-7
Interpretatial: simple greater th.an canp3.risioo for the
A
numbers X and Y. Note t..."la t NIL is returned if ei. t.~er
G. AssignJ1lent Functions

Assignment funetialS are nomally used to assign values to prcqra..ll


P. Logica..l FunctioQS variables.. For instance, they permit the values of a function's focnal
arguments to be mcdified w ithwt the neea for a rec.trsive func+"....icn call.
'.the logiCal funetia1S permit Boolean ccmbinatia\S of truth values 'rhus in some situations they can significantly improve a program's
like these returned by the rec:cqnizer and cauparator functions. Here as exeoJtioo speed. If t.'le variable bei.n; assigned is not a local variable
elsewhere in muLISP, any non-NIL value is considered to be logically (i.e. not a formal argument of the currently executing function), t..'e
true. . assignment w ill remain in effect even after the fWlction is exi ted.
As 'Ii i th the modifier functions described above, this phenomenon is
called a side-effect of the functicn.
1. ON N:Tr [Xl :.
EO [X, NIL}; Use of the function SE'!Q should be familar to programmers of more
conventional languages such as B:..5IC and PASCAL where the assignment:.
Interpretatial: 'tt1e lo;ical N:JT funeticn returns T if and statement is used pervasively. 'Ihoogh po.Ierful, irrliscriminate use of
. only if its argument is NIL. 'Ibus it is entirely the assignment fW1ctions will resul t in unstructured programs and
EqUivalent to the funetiQl NOLL. detrimental side-ef£ec-~ which are exceedi.rx;ly diffio.llt to Cetug. To
prevent developing bad habits, the nov-ice LI-q> prcgramme.r shcc.ld avoid
use of these funeti a1S as they c::i:)soJ.re the elegant, as;ll. ica tive na t:ur e
2. CBN}NO [Xl, :a, ..., XIl] :- of the la.nguage..
if n=O -> 'mOE; I
WI' [NA[, [Xlll -> NIL;, 1. CfN SET [X r Y] :-
IrND [X2, X3, ••• , xn]; RPLl£:A. [X, Yl,

Interpretati00: 'the logical }NO funeticn returns T if am


c Y;
Interpretation: Set the value of the name X to "I, and
only if each of its arguments evaluate to a non-NIL return Y. Note that the function is also def.ined '"hen
value. Note that AND is a CBN functicn and that its X is not a name: nGlever, its use in that situatioo is
arguments are sequentially evaluated until one strmgly discoo.raged.
evaluates to NlL or until: all have er,raluated to a non-
NIL value. Hence not necessarily all the arguments
wUl be evaluated.
2. Ci3N SE:.IQ (X, YI :-
sar [X, fJl~ [Y]];
3. CBN CR [Xl, X2, ••• , J(1) :-
if n-o -> NIL;, Interpretaticn: Set the value of X itself to the value of
'DIN:.. [XlI -> 'IRJE;, . Y, and return that value. ~ functioo is used mct'e
CR [X2, 0, ••• , Xnl; often than SET because usually it is desired to assign
a value to a variable rather than to the value of a
Interpretatiau 'the lcgical CR funeticn returns T if art:i variable.
../
one of its arguments evaluates to a non-NIL value.
The arguments are successively evaluated and if any
evaluates to a non-NIL value, T is r.eeurned and none
of the remaini.n; arguments are ev-aluat:ed.
(J 'Ihe distinction between the effect of SET and SE:lQ on t."'leir
arguments is demonstrated by the folla« ing. If the value of DCG is
BARK.. then
SE'JQ [I:X:X;, • (A B C)!

v ill change the value of ocx; from BARK to (A B C). In' contrast, if the
value of tCG is BARK, then

SE:r [IX:C, '(A B C) 1

v ill change the value of BARK to CA' B C) I and the value of OCC 'J ill
remain BARK.

./
t
v-g

,- ...
B. Property Functions

Pr~ty functiQ'lS prc.vide an excellent means of associating glcbal


3. CBN roP [Xl := properties with names. A name's property list is used to store these
PO~l [X, ~AL (Xl); properties along with indicator tags. The property value associated
~ \lith an indicator can be retrieved at any later time using the GET
CSl :EOPl [X, Y] : . funetioo. Used in coojuncticn \II ith t:."le flag functicns described in t.~e
SET [X, CDR (Yl];, next section, extremely flexible and efficient data bases can be
CJ\R [y]; established in a very natural and coovenient manner.
Interpretation: If X is the name of a list, then POl? {Xl
returns the car of that list while setting X t.o the 1. CS1 ASS:t:. (X, Y] :.
cdr of the list. 'Ibis operatiQ'l is the LISP analcg of ATOM (Y] -> Y; I
the famllar pc7J? stack operation. widely used in macbine A'D:M. (OR (Y]] -> NSSX. [X, OJR (YJ 1; ,
languages. IOUJ;.L [CAAR [YJ, Xl -> CAR [Y];,
ASSfX. (X, CDR (Yl J i

4. CBN roSH [X, 'Yl :- Interpretatim: This funeti<n performs a linear searc..~ of
~ [Y I cx::NS {EVN. {Xl, alN... {Y] I ] ; the association list Y, looking for a non-atomic
element whcse car is EQtJ}L to X. If f~ the ent:Lte
Interpretation: If Y is the name of a list and X is an element is returned; otherwise NIL is retUrned.
./
e.xpressi~ then posa (X, Yl wi l l coos X onto the list
Y and update. Yto point to this enlarged list. This
operation is the LISP equivalent of pushinq infor- () 2. cz.J GE:r [X, Y] ::a
maticn CI'lto a stade.. X <- P:SS!X. [Y, CDR [X]],
MI:M [X] - ) NIL;,
CDR [Xl i

Interpretation: GET [X, Yl returns the property value


associated with the name X under the indicator Y. U
the indicator is not found, tb.en NIL is returned.

3. ~ POT [X, Y, Z] :-
NJLL [GE:l' [X, Yl] ->
RPLJa) [X, cntS (cx::NS [Y, z1, Q)R [Xl]],
Zi,
RPLJa) [ASS:<: [Y, aJR [Xl}, %1,
Zi
Interpretaticn: roT [X, Y, Z} places en the pr~ty list
() of the name X under t.~e indicator Y the pr~ty value
z, destrOfing arrj prtNiOJS value.

4. CSJ REMProP [X, Yl :-


MOM [am. (X]] -> CDR [X];,
~UAL [CAACR [Xl I Y] ->
Y <- a:wJR [Xl,
RPLKD (X, CDR (XI], Y;,
~p [CDR [Xl, Yl i

Inte.rpretatiat: REMProP (X, Y] remcwes fran the pr~ty


list of the name X the property value assccia ted w i t.b
the indicator Y. It. returns the prq;E..rt:.y value.

V-ll

V-lO 3
J. Definition Functions
) . .
I. Plag Pu~ctions 'Ihe funeticn definiticn funetioos are the auymeans of access to a
name's functioo definiticn cell. When a function is defined using Pt1ID,
Like the property functions the flag functions also use a name's
property ,list to stQCe information. HGieve.r,tbe name is only flagged
" the definitioo is pseudo-compUed into an extremely dense fern called
D-Code or Distilled Code. This compilation results in about a 3 fold
increase in code density and approximately a 20\ improvement in
as either having a pa.rtiOJlar attri.l:ute or not. execution speed over muLISP-79. The compilation of S-expressions
containing cdr cells which. point to non-NIL atoms results in t..~e
1. CIJ1 FL1GP [X, Y} :- replacement of the atom by NIL. In 9~neral it is recommended that.
QUOTEd non-atomic constants HO'l be included in function definitions
MEMBER [Y, CDR (Xl]; directly. Instead, the constant can be assigned to a name· whic..~ can be
used in the definitial in place of the constant. 'lhe irNerse precess of
Int:.e.rpretaticn: This predicate w Ul return T if and only de-compil.ing D-code back into a linked list also cccurs. autanatically
if the attribute Y is an element of the property list . wben GE'!'D is used to retrieve a definition. '!bus the use of o-code is
of X; and NIL otherwise. Note that if Y is an invisible to the user and the interactive nature of LISP is not
indicator put on the property list by using the POT canpranised in the interest of efficierv:;y a.OO. can~
function, it: w ill only be recognized by the function
GE'r and not by FL1GP. 1. CSl GEm (Xl :-
N:1l' [WME [Xl] OR ONOEFImD [X] - ) NIL;,
SCBR [Xl at FSOBR [Xl - )
2. ON FI../A.G [X, Y] :-
FL1GP [X, Y] ->
RPL1£D [X, <XNS [Y,
y;
c:::oa [Xl)],
o mema:y address of machi.ne lan;uage subrcuti.ne;,
the 5-expression EqUivalent of the D-caie defini.ng ·the
funetim X;
Y;
Interpretaticn: '!his functicn is used to get a functioo's
Interpretaticn: FI.1G [X, Yl wUl flb; the name X with the definition for further processing. If the functioo is
attribute Y by making Y t:b.e first element of the a machine language subroutine, the physical memory
property list of X. address of the function is returned. Othe.rw ise the
.. linked list SIUivalent of the O-Co:1e is returned. see
sectioo V-O foe the definiticns of ~ and FSCBR.
3. CiJI ~ [X, Y] :-
Mai [CDR (Xl) --> NILJ, . 2. CSl PtrlD [X, Yl :.
~ox. [Y, CADR [X] 1 -> !Dr [NAME [Xl 1 -) NIL;,
. RPL1£D {X, CIJCR {XlI, ~ [Y]-)
, Y;, functim cell of X ( - address given by Y;,
REMFL1G [CDR (Xl, Yl; functioo cell of X ( - D-cc:de tqUivaleot of Y,
Y;
Interpretation: This function remOV'e5 the attribute Y
frantbe property list cf the name ~ returnin9 NlL if Interpretation: If Y is a number, PO'ID [X, YI sets the
the attriblte is not: fcx.md. Q functim cell of X to the memory address EqUal to tl1e
rumbe.r Y (mcdulo 64K). Otherwise the definitim cell
:' is set to the D-code equivalent of Y. The procedure
fcx using PO'lD to link to machine lan;uage subroot.ire.s
is described in ~ C of this mam1a.l.

3. ON MJlD (X, Yl :- .
tOr [WME (Xl] OR N:1r [WME (yl} - ) NlL;,
functicn cell of Y ( - funct1oo' cell of X,
GElD lYl i
Interpretation: Set the function cell of Y to point to
the same memory location as that of t.~e functioo cell
of X. In cases where a MeND is sufficient it should
be used instead of a. GETD and POTD.
E. Sub-atomic Functions ) 3. CSl UN:;1'B (Xl :-
W'ME (Xl ->
'!'he sub-atanic funetia1S al:e so named because they prO/ide access to the number of characters in the print name of x; I
a name's print name string or a number's number vector. This makes it WMBmP {Xl ->
possible to temporarily unpack. an atom's print name, operate on the the rum.ber of digits in the print name equivalent
resulting list of characters, and ulti:ma.tely repack the list to form a of X;,
rvN name. In additiat to its sub-atcmic capability the Lm:i'm ftmeticn A'J.t:M [a:>R (Xl] -> 1;,
determines the top-lfNel length of an. 5-e.xpression. 1 + r..m:;-m (CDR (Xll;
Interpretations: This function is effectively three
1. aN Pia [Xl :. functions in one. The value returned follows
MIli (Xl -> .W;, intuitively fran the data type of its argument:
NH1E [CAR (Xl] - )
coqcatenate the print name of CAR [Xl with a. U X is a name, the number o~ characters
PN::K [CDR {Xl J and return the result:inq name:, act1Jally r6:iuired to print X is returned. '!be Clrrent
tl:1MBmP (CAR [Xll -> value of PRINl. is taken into acco.mt while canp.lting
concatenate the print name string of the number this length. The effect of PRml is described under
CAR (X] with PACK [CDa [XII and return the the control variable subsection Wlde:: the Printer
resulting name;,
,!
PPa [aR [X]]; c FunctiCX1S•
b. If X is a number, the number of characters
Iilteri'retation: This fune:tion, called COMPRESS in some actually rEqUired to print X is returned. The current
dialects of LISP, returns a name whose print name is a radix base and if applicable the leading ._- sign
pacXed versioo of the print names of the atans in tbe and/or leading ·0· are properly taken into account
list X. '.the curren\:. Ici\DIX base is used. to determine wbil e canp.1tin; this length.
the print name string of numbers.. Note that PACX
always returns a. name, e9'en if it only contains c:. If X is a non-atomic, the number of top level
digits. As shewn in the muLISP library file, PPa., can nc:X!es in the list is returned. As always in muLIS2, a
be used to write a ~ (generate symbol) functioo.. a:!r which is atauic denotes the tecn;mtor of a list.

2. CIN CNP.ACX [X] :-


NAME (Xl - )
a list of names whose print: names correspond to
the characters in the print name of X;
!IlHBERP [Xl - )
a list of names whose print names are numerals
ccrrespaldi.ng to the digits of X expr::essed in the ()
OJrrent radix base;,
NIL;

Interpretation: This function, called EX!JLODE in some


dialects of LISP, returns a list of names whose one-
character print names correspond to the successive
characters in the print name of X. '!be current radix
is used fa: numbe.cs an:3 digits are cemrerted to names
with single numeral print names.

:)
V-14 ' I F ' ,..
I.. Numerical Functions K. Reader Punctions and Control Variables
'l11e reader' functiQ1S provide for character inpJt to muLISP programs.
'I1le numeriCal funeticns implement exact pred.sial integer arithmetic 'lhe functiO"1S read characters fran the current input source. 'Ibis i..n;:ut
foe numbers of magnil::1.lde up to 2-2032-1, or atxut fill decimal digits of source can be either the console or any text file on the disk or other
accuracy. If noo-numeric arguments are passed to any of the fun~-icns secondary storage device. The current input source can be controlled
or if an OIerflGl occurs, the function returns a value of NIL. Division through t."le use of the function RDS in conjunction with the control
by zero by anyone of the functions OUOTIENT, REMAINDER, or DIVIDE variable RDS.
causes the follcwing warn.ing message to be displayed on the ccnsale:
ZERO Divide Error 1. aN RDS (X, Y, Z] :- (ReaD Select)
WLL [Xl - )
and the functiat returns a value of NIL.
, Res <- NIL;,
, NAME [Xl AND tw1E cY] ->
1. ON MlNJS [Xl :- WLL [Z] ->
N:JMBmP [XI - ) -X; a file named x.y exists on the currently
NlL; lcr;ged in disk drive ->
~ X.Y for ~t,
RDS <- X;,
2. C'Sl FLOS [X, Yl :- RDS ( - N1L;,'
N1lME (Z] ->
NJMBmP [Xl AND 00HBmP (Y]
NIL;
X + Y;
-> o a. file named X.Y exists (Xl drive Z
open X.Y en Z for i.npJ.t,
->
RDS <- X.,
RDS <- NIL:,
3. CfN D~ [X, Y] :_ RDS <- NIL;,
ROS <- NlL;
~ [Xl I.ND mMB.ERP cY] ->
X - Y; Interpretation: The read select function is used to
NIL;
select an i.npJ.t scurce file. If the selected file is
found, the file is opened for input, and the value of
4. C'JN ~ [X, Y] :-
the variable RDS is set to the name of. the file. 'ImlS
this file becomes the new current input source. If
N:JMBmP [Xl JND NOMBmP cY] - ) RDS is called with no arguments, invalid arguments, or
X • Y; if the file is not found, the variable RDS is set to
,NIL;
NIL mak.ing the ccnsole the OJ..rrent i..nput soorce. '!be
defaul t DRIVER function sets RDS to NIL. This makes
s. aN O ~ [X, Yl :- the coosole the current input soorce a1 initial system
startup a.OO a.f ter interrupts or error traps.
N.H)ERP (Xl RID mMBEm' [Y] ->
X/Y (Truncated tGlard zero); ()
NIL;
2. CBl RMr:M [] :- (Read MtM)
Interpretatia1: 'l11e truncated integer quotient. read one token from the current input source and
return the correspcnding name or number. A token is a
str i.n1 of characters de.limi ted b-f ei t.~e.r separator or
6. CSl RDOOlmm [X, Yl :- break characters. See the notes at the end of this
secticn for details on including camnents ard quoted
D ~ [X, 'rIMES [Y, OtX1rIEm' [X, Yll]; strings within a token. Unlike separators, break
characters are returned by RA1'OM. as single character
7. CI!N DNIDE [X, Y] :. LISP names. The RAWM separator characters are:
WMBERP [Xl AND Nt»-1BmP [Y] - ) space, carriage return, line-feed, and tab (CTRL-I).
The RATOM break characters are: ! $ & I ( ) *
cas [Qt:X:>T:tmr {X, Y], REMAINDm [X, Y] 1; + , - . / @ : i <. >? [ \ 1 A ,
NIL;
{ I } - \

-....
v-'~
3. CJN READ. []: =- (READ Expressic:n)
REAOO (RAni [1 J; 4. 0fJ REAtCH (1 :- (READ <JiaracteJ:)
· read me c..'1araeter fran the current inp.:lt soorce and
~ READO [Xl :- l return the correspondinq LISP atom. A number is
III [X, '( J -) returned if the c..'1araeter is a decimal digit less than
REAtLIST (MIM (J 1;, , the current radix base.
10 [X, • [ 1 -)
~ {RFJ1ZX..IST [RAni (]], RA'IM []];,
EO [X, ') 1 OR EO {X, '. 1 at EC (X, 'J J _) Notes:
READ [1;,
X; . 1. If a disk file is the current input source and an
attempt is made to read past the end-of-file (WF), the
CJN RF..AI:'8R1CKET [X, Y] : • foll~ in; warning message is displayed en the coosole:
EO [Y, • ) ] OR BJ (Y, '] I -> X:,
<XNS [x" ~ {RFJ1ZX..IST [Y], RA'IM (ll]; End-of-Plle R.ead

CSt RF...hJ:LIST [X 1 : - In additioo, the Caltral variable RDS is set to NII.. making tbe
'mU-ilN.A'IOR (X 1 -> NIL;, coosale the e::utrent int;ut scurce.
1Q [X, '. 1 -)
RE.N::J:OT [READ [], RA'IM [] 1; , 2. Caa.ments can occur anywhere in the text of the input
ens (REAOO [Xl, REAlLIST [RAni [ll]; soorce so loog as thej are delimited by mate.hi.ng percent sigr.s,

QJI RF.N:COr [X, Y] : •


o -,-. '.the text of comments is totally ignored by the functions
-- RAIDM and RE.Nl. acwever, the fcnctioo R.EArXlI reads and returns
~ [Y] ->X;, percent signs just as any other character.
a:NS (X, RFJlLLrsr [yll;,
3. Special characters such as the percent sign, double
C'1!R ~ [Xl :- quote sign, separator characters, and break characters can be
BJ (X, I) 1 -> 'mOE;, read in as names or: parts of names by the use of quoted strings.
!Q (X, .] ] -> SUCh strin;s are de.l.im.ited by double quote marks. 'Ibe dccb!.e
. unread -]. character back into input: source for quote can be included within the string by using two adjacent
the next &ml read, double quotes foe each. desired double quote.
'ImJ'E; ,
NIL; 4. As an ad:3ed programm..i.ng et:nlenience, wben a nam.e is :ead
into the system by READ, RAmM, or RE.ADCB, the value of the
aN &ml [] :- variable RAIDM is set to the net name.,
read one token from the current input source and
return the corresponding name or' number. This
function is identical to RATa!'! except: the RATM
separator characters are: space, comma, carriage
return, line-feed,. and tab; and the RATM break ~J
characters are: ( ) • [ J See the notes belOtl
fer details cooce.rning caxments and quoted strings.

Interpretation: The READ function reads one complete


symbolic expression from the current input source
while <:a1Structing the EqUiValent LISP data structure.
Well formed expressions using either the list
notation, dot notation, or a combination of both are
acceptable means of input. Brackets can be used as
super-parentheses. Thus the right bracket, -].,
closes all left parentheses back to either the
beginning of the expression or to a matching left
bracket:. Extra right parentheses, right brackets, and
dots cUe ignored.

V-1S .-~ V-19


!be reader control variables extend the flexibilit::t of the reader
'I11e reader control variables extend the flexibility of the reader functioos by making several i..npJt optioos available to the user. They
operate as flags or toggles which are eit.~e.r off or on. Except for
functiCXlS by making' several i..npJt opt:ioos available to the user. They ECHO, the reader control variables have the same names as the reader
operate as flags or toggles which are either off or on. Except for
ECBO, the reader control variables have the same names as the reader functia1S. 'lhis is dooe primarily to ccnserve preciOJS memory S-t4ce ;
bcwever, each variable is usually used in conjunctioo with the functioo
funetialS. 'Ihis is dale primarily to <:a1Serve preciQJS memory space; of the same name..
hew ever, each variable is usually used in conjunctioo with the functicn
of the same name.
1. RDS: Normally control of the current input source is
1. RDS: Normally control of the current input sou~rce is done through the use of the function RDS as described above.
BGiever, after a file has been opened and made o.u;rent, cootral
done through the use of the function RDS as described above. can be returned to the ccnsole withc:ut closing the i..n;;:ut file,
BOIIe/er, after a file bas been opened and made current, cootrol . simply by settdng the value of PnS to NIL. A subsequent non-NlL
<:an be returned to the consale withcut closing the i..npJt file,
simply by sett.in; the value of ROS to NIL. A subsequent non-NIL
assignment to RDS w ill then return control to the previously
~ disk. file at the point at which readi..D; ..,as suspended.
assignment to RDS w Ul then return control to the previously
cpened disk. file at the point at which. readi..D; was suspended.
2. READ: 'l11e variable READ cootrols the IGier to u-pper case
2. READ: 'nle variable READ coo.trols the IGle.r to u-pper case coaversicn of letters upon inpJ.t. Ncrmally READ is r:m-NlL ar.d
coaversicn of letters upon inpJ.t:. Ncrmally READ is r:oo-NIL and
lower case letters are distinct from their upper case
COJnterpu'ts. BOt/ever if it is NIL, all 10ller case letters are
lower case letters are distinct from their upper case . converted to uppe.c case as they are read in. In arry case, all
CCUllterpu'ts. Hcwever if it is NlL" all lGle.r case letters are
I

. converted to upper case as they are read in. In arr:l case, al.l lGier case letters alreadj in the system remain in 10ller case.
10tler case letters alread:i in the system remain in lGler case.
3. R.EADCB: When the console is the current input source,
3. R.EADOI: When the console is the current input source, the console input mode is controlled by the variable REAOCB.
the console input mode is controlled by the variable REAOCB. Nocnally the value of the variable .R.EAIX:B is non-NlL and console
Nocnally the value of the variable .R.EAIX:B is non-NIL and coosole i.rp.lt is then in the line edit mode. In this merle, when all the
i.np.lt is then in the line ·edit mode. In this mede, when all the characters have been read fran the current lln~ the operating
cbaracters have been read frem the current line, the operat.ing system's line edit rwtine is called foe further i.np.lt. Until a
system's line edit rwtine is called foe further i.rItUt:. until a . carriage return is typed.. the system's normal editint; procedures
. carriage return is typed.. the system's normal editint; procedures such as input echoing, backspacing, line deletion, printer
such as input echoing, backspacing, line deletion,. printer output toggle using control-P, etc. are in force.. If the
output toggle using control-P, etc. are in force.. If the variable R.EMX:B is NIL, all buffering and input echoing is
variable R.EADCHis NIL, all buffering and input echoing is eliminated. 'this x:av input mode is useful for immediate
eliminated. This raw input mode is useful for immediate response to ale dJaracter cemmatXis as dem<nstrated in the LISP
~
respoo.se to au! dJaracter canmands as demCDStrated in the LISP STAR edi tor. IJ
STAR editor. (J
4. FX:BO: If a disk file is the aIrrent inr:ut source and the
4. fX::lO: If a disk file is the current int:ut source and the value of the control variable ECHO is non-NIL, the characters
value of the control variable ECHO is non-NIL, the characters bein:3 read fran the file are echoed to the alrrent cutpJt sink,
be.i.ng read fran the file are echoed to the current cutpJt sink, which is usually the console. Note that since canments are also
which is usually the coosole. Note that since ccmments are, also echoed, English language text within a canment can ca:rJenie.ntly
echoed, English language text within a canment can cOCNeniently be displayed wi thoot having to actually process the text. see
be displayed withoot having to actually process the text. See the pr:inte.r· cmtrol variable secticn for other effects of EX:Bo.
the printer cootrol variable sectial fa: other effects of a:sa.

,,,.....
~,._"'\I\

<~
V-20
3. CSJ mnn {Xl :=
.WME [Xl ->
. OJt:pJtto the Olrrent ootpJt sink the print name
R. Printer Punctions and Control Variables representation of Xi,
~ NOMBERP [Xl - )
output to the current output sink the digits
'lbe muLISP printer functioos direct character oot::put to the cw:rent
output sink. As determined by the function and variable WRS, the expressing X in the current radix base and
sink can be either the console or a disk file. preceeded by a --- if MINJ~ (Xl;,
PRINl {tl ("1,
1. aN was (X, Y, Z] :- (WRite Select) PRINt.IST {X I ,
roT N.lIL [WRS 1 -> x;
write out the final record of the currently open
disk file and close the fUe,
WRS <- NIL, . ON PRINLIST [Xl :-
WRS [X, Y, Z];, PRINl, [OR (XlI,
HJLL (X] - ) roLL (CDR [Xl] -> PR.INl [") "1;,
,WRS <- NIL;, - PRINl (" -],
NAME [Xl }N) NJ\ME [Y] - ) A'JIX~ (CDR (XlI -)
HJLL [Zl - ) PRINl [". -1,
on the currently logged i.n disk drive, if a PRINl (CDR (Xl}, (
file named x.y exists delete aIrf ex.is~ file PRINl (")-1;,
named LBAK, then rename the file LY to PRlN[.,IS'I' [CDR [X 11 ;
~ and make a new directorJ entry for: x.y,
WRS <- X;, Interpretation: The function PRDn will output the
NAME [Z] - ) standard list notation of the object X to the
on drive Z, i f a file named LY exists delete cw:rent outplt sink. X is the returned value.
art:! existi.nq fUe named x..BAK, tbenrename the
file LY to LBAIt, and make a new directory
entry for LY, 4. CSl TfRPRI [Xl :-
WPS <- X;, ZEroP [Xl -> NIL;,
was <- NIL;, cutp.1t a carriage r~turn and lii1e feed to the current
WRS <- NIL; cutl;Ut sink,
PLOSP {Xl }NO LESSP {X, 2561 ->
Interpretatiat: '!'he write select: funetiQ1 is used both to 1'fm'RI . [X-ll ; ,
select and later to close output sink disk files. NIL;
U t:.b.e current output sink is a disk file and WRS is
call. ed, that file is closed. Next, if a file name, Interpretaticn: If X is a ncn-negative n.nnber, 'mu:'RI (Xl
type, and a drive (cptiooal) are su;;::plied as arguments outputs X number of new lines to the cw:rent output .-,

to WRS, an already existing file of that name is sink. Otherwise ale n&I line is cutplt to the sink. U
renamed to a .BAK file of the same name. This
prarldes an autanatic one lfNel file backup feature.
Pinally a new fUe of the given name and type is s. CBI Sp]QS [Xl :-
created for output on the appropriate drive, and the PLOSl? [Xl AND LESSP (X, 2561 ->
variable WRS is set to the name of the file. Thus
this file becomes the new current output sink. The
m.nn. t- -1,
default DRIVER function sets WBS to NIL making the SP;v:ES (X-ll i , ..
the current OJrsor I,X)Si tioo:
console the current output sink on ini tial system
st:a.ctup aId after interrupts or error traps. Inte.rpretaticn: If X. is a noo-negative number, SPACES [Xl
OJtt:uts X number of spaces to t."'le o.trr ent OJ t;:ut: sir.k..
Otherw ise no spaces are output to the sink. In any
2. CBJ mINT [Xl :- ease, the resulting cursor position is ret:u.rned.
E'R.INl [X 1,
'I:ERPRI [1,
X;
Interpretation: Print t.."le expression X,. terminate t..~e
last line and return X. V-22 I~)

V-21
!he printer cootr at variables a.re used a.na.lo:;ccsly to t.'1eir reade.r
cootrol ccunterparts. 'll1ey function as to3g1es to control the current
6. CBl LmELEXmi (Xl :- outp.tt sink, case conve.rion, printing of quot.ed strings, and output.
~J GRF.A.TDtP [X, ill ;NO USSP [X, 2561 - ) echoing of characters to the ccnsole.
set ma.x.imum ootpJt linelength to X,
return the previOlS linelength;,
return the current linelength; 1. WRS: Normally cootrol of the OJrrent cutplt sink. is dale
through the use of the function WRS as described above.
Interpretation: If X is a number between 11 and 256, However, after a file bas been opened using WRS, output can be
LINELEN:;TB [Xl sets the ma.x.imUItl number of c.~acte.rs directed to the coosole without closing the disk file '01 simply
output per line to X. The fWlction returns the setting the value of WRS to NIL. A subsequent non-NIL
previous llnelenc;th. If X is not a number or cutside assignment to WRS VI ill then redirect cutput to the disk file and
the permissible range, the current linelength is a.~ data alto the eOO of the' file.
returned. '!be defaul t linelenqt:h is 72.
2. PRINT:' The variable PRINT controls the upper to lo.rer
7. C!N RADIX' (Xl :- case conve.rsicn of letters be.in; ootp..1t. Normally I?R!NT is noo-
GREAtmP [X, 1] AND ussP [X, 37] -> NIL and all letters are printed as stored. HC'Jever, if it is
set radix base to X, N!L, all ua?& case letters are cawerted to lcwer case as they
return the old radix ~:, are printed. This conversion in no way affects the internal
return the current radix base:

InterpretatiCX1: If X is a IJJmber between 1 and ':rT I R}D!X


storage of arr:I name's character strin;.
o
[Xl sets the radix base in which numbers are expressed 3. P1UNl: If PRINl is NIL, names which contain separatot' or
for both input and output, and the function returns break characters w ill be printed using double quotes as
the previous base•. If X is not a number or outside necessary to permit the name to be S\.1bSEtIUently read back in as
the permissible range, the current radix base is the same name. Printing such names using quoted strings is
returned. '!be defaul t .radi,x base is decimal ten. essential for such applications as LISP editors. Normally,
bOJever, PRINl is non-NIL and a name's print name string will
. simply be outt;ut as is.
Notes:

1. If a disk file is the current output sink and there is ~. .. '. 4. ECBO: If a disk file is the current output sink and the
insufficient disk space, the following warning message is value of the control variable ECHO is non-NIL, the characte.r:s
displlr'Jed a\ the <:a1SOle: beir¥; ou.t;ut to the file are also echoed to the coo.sole.
_0 Disk Space

In additioo, the caltraL variable WRS is set to ~ makinc; the


coosole the current cutpJ.t. s.ink. ()
2. If the host computer's operating system supports a
printer and muLISP is in the line edit mode (see note 3 under
reader control variables, section V-H), typing a C!RL-P v Ul
direct all muLISP cutput di.spl~ed en the system. coosole to the
printer as well.

V-24 (l
V-23
4) OtheN ise the task. is reo.trsively evaluated ~ a funeticn
o. Evaluation Functiol1S body itself before continuing with the evaluation of the top
level t:-unetim body. '!his permits conditiooal forks in funetim
) The ev~uation functions are used for expression evaluaticn and bodies to later recanbine.
program control. 'n1e algorithm for evaluating functim bodies in muLISP
has been enhanced to make pro;ram control implicit in the struet:ure of
the body itself. As discussed in section I-E p this makes function This e·laluation scheme is very powerful but it does not have any
definiticns cleaner, sha:ter, and easier to interpret:. provisicns for non-ceo.u:sive pro;ram control structures. SUch iterative
capability can be added to the algorithm above quite simply. A func+'~oo
A muLISP function definition is spe<:ified by a linked list body enclosed ·w ithin the LOOP control construct w i l l be evaluated as
representing the desired definition. The first element of the list described above, except ffNaluatioo will start again at the begin."l.ing of
determines the functioo's type. It shOJld be either the name· L.A:1BDA or the body instead of returning after the last task has been performed.
NL.AMBDA. LAMBDA indicates the function is a ca.l.l by value (CBV) '!his ccnt..irnJes until a predicate as defined in case 3) above is non-NIL.
functioo. When a CSJ functioo is eal.l~ arguments are first evaluated 'rhe value of the'loop construct is the value of the function body
and only the resulting values are passed to the fW1ction. A function follGl ing the noo-NIL predicate.. Note that any rnJin.ber of predicates can
defined using &LAMBDA (i.e. a Ho-eval LAMBDA) is a call by name (CBN) 0C0lr within a loop at arrJ desired locatioo. '.this implementation of a
function. A CBN function receives its arguments in unevaluated form~ LOOP preserves the basic evaluation met.'1od of muLISP while greatly
just as they- were given in the call to the function. C3l functicns are impra.Tinq the pe.rfoon.ance of the language. .
by far the most prevalent in LISP. 'Ihus the rlC"ice prcgrammer need not
be concerned with learning to use the CBN fW'lctions until the other r
''-..-
features of the language have been mastered. '!be follG/ ing auxiliary functiCX1S are recognizers used to define the
ernluatioo. and functioo definition functioos..
'l1le second element of a function's definition should be either a
name or a list of names defining the function's formal arguments. If
the formal argument is a name which is not NIL, the function is aN ONDEFINED [Xl :- (~ined func+-..icn recognizer)
<:a1Sidered to ·be a no-spread functioo. A no-spread ftmcti<n receives NtIIL (GF:lD (Xl];
its arguments as one list baJnd to tbe name. 'I11US no-spread functicr.s
can have an arbitrary number of arguments. However, if the se<:ond
ele:nent is a list of atems, t:be arguments will be passed to this· spread ON o:NP (X] :- (call-by-value reco;n.i%er)
tunct:ia:l boJnd to each formal argument maki.D; up the list. Note that a StBR. [Xl ca FXPR [Xl;
function's being spread or: no-spread is entirely independent of its
bei.rx3 CIN or CBN.
C1N CBNP [X] :- (ea.u-o:r-na:me recogni.z er)
'I!1e remainin;; elements of the list make up the Cefinitiat's flmctioa FstER (Xl ~ FDl'R (Xl;
body. '!he functicn body is a list of tasks which are to be successively
performed when the function is called. 'nle returned value of the
functioo is the value of the last task perfooned. RGI a given task is CEN SJBR (Xl :- (C'iN subrootine recognizer)
to be performed depeOOs en the structure of the task, as follGls: X is a CfN machine language rootine - ) -mJE;,
NlL;
o
1) If the task is an atom, the value of the task is the
value of the atan.
ON FSJBR [Xl :- (CBN· subrootine reccgni%er)
2) If the car of the task 1s an atom, the car is considered X is a CBN machine language rcutine -> -mJE;,
to be the name of a function which is to be applied to the list NIL;
of arguments making up the cdr of the task:.. '!be azguments are
ervaluated before the at=Plication for CBl functioos.
CSl EXPR [Xl :- (aN ~ defined functicn
3) Ifthe car of the car of the task is an atom, the car of EO [eM (Xl, .~]; r eccqniz er)
the tas!< is considered to be a predicate, which is then
evaluated as described in 2) abov-e. If the value of the
predicatF! is NlL, the value of the task is NIL. Hcwever, if tbe ON F'EXt'R (X 1 :• (CBN ~A defined fun~...iCX1
predicat.e's value is non-NIL, the original function body is EO (CAR (Xl, '~l; reccqniz er)
abandooed an:i evaluatim prcx:eeds using the cdr of. the task as
the new functi Q'l body.

V-2S
x
[CAR [Xl I CADR [Xl, NIL};,
X [CAR [Y], ChDR [Y], OJDR (Yll;,
) FSUBR (GElD [Xll ->
1. am Q~ [Xl :- x (:fl;,
X; !XPR [GElD {Xl] OR FExPR {GElD (Xl] ->
BnD [CADR {GElD [Xl], Yl,
Interpretation: This function suppresses evaluatioo of Y <- FYAI.2JIf:l (NIL, CDOR {GElD (Xl]],
its a.rgcment and r et:urns the object X i t:sel.f. UNBIN:> (CADR (GF.:ID (Xlll,
Y; ,
NIL;,
2. CIN FJl}L [X] :- aPR [Xl OR EtXPR [X) - )
Ami {Xl - ) O\R [Xl;, BIro [CADR [Xl, Y],
NAME (CAR [Xll -) Y' <- FYA'!..2I:rfI (NIL, CDOR (X] I ,
~INm (CAR {X} J -> ONBIID (CADR [XII,
EO (C1a [Xl, fJlM.. [C\R (XII] - ) Y; ,
elLIS (Xl;, NIL;
fll1-L (aNS [E\T~ loa (XII, CDR [Xl] 1;,
CBlP (GElD [OR [Xlll -> Interpretation: APPLY {X~' YI applies the function X to
N!PLY [CAR [Xl, EVLIS [C!:IR [Xll];, the list of arguments Y. If X is a machine language
03NP [G~ {~ [X}]} -> routine, control passes to the routine. If X is a \
'-'
MfPLY [CM [Xl, CIJR (Xl];,
I..AMIDA defined f~~on, the formal arguments of X are
DlLIS [Xl i,
temporarily bound to the actual arguments, the
EXPR [OR [XIl -> function b<Xiy is evaluated, the origi.rlal values of the
IJ!I'f.;y[CAR (X 1, DlLIS [CDR {XIll; ,
. FEXl?R [<:Nt [Xl] -> formal arguments are restot:cd, and the value of the
IJ!I'f.;y {OR {Xl, QJR {Xl];, fur¥:ticn b<Xiy evaluation is retu~
DlLIS {X]; .

Interpretation: If X is an atom, 'EYM" [Xl returns the c:sv 'iYN:..2aJY[X I Yl :•


A'ltM [Yl -> X;,
contents of the value cell of X. OtbeN ise, i f the
car of X is a aN funeti~ each element of the cdr of A'ltM {Ct\R (Yll OR A'ltM [CAAR [Y]] ->
f:m2I:D'! (EVAL [CAR [Y] 1, Q).R [Yll;,
X is evaluated and the function is applied to the A'ltM (Ct\AAR [Y] J ->
results. If the car of X is a CBN function, tl1e X <- EVAL [CMR {Y]],
function is applied to the cdr of X directly. N.Jr [Xl ->
. pinally, if the car of X is not a function,. each
element of X is evaluated in turn, and a list of the FYN..N:1J'f (NIL, CDR [Y}];,
~ [X, <:DAR [Y]];,
results is returned.
FYN..N:1J'f (EV'AI..'aCDY (X, CAR (Y] 1, CDR (Yll;

CBl alLIS rx 1 :. Interpretation: This function evaluates a fur.d:ion b<Xiy y


as described in the introduction to this section and
o
A'l'a1 (X 1 -> NlL;,
returns the value of the last expression which was
a:t'S [EV'N.. [CAR [XI], elLIS [CDR {XII];
eva.l1Jated•
Interpretaticn: 'lbis func+'...ioo evaluates each el ement of a
list and returns a list of the results.
CIN BnD [X, Yl :-
ATCli (Yl ->
3. CSl};WI.:! [X, Y] :- A10i {X] -> NIL;,
pUgJ (EVAt [CAR (Xl] ~l,
NN1E {Xl -> SEr [(AR (Xl, NIL},
I

CNDEF~ {Xl -> BIND (CDR (X], :fli,


EO [X, f)J[4L {Xl] - ) NlL;,
MfPLY (SIAL IX), Y];, Ami (Xl - ) NIL;,
StJBR [GEm [XlI -) PO$ ( EVAt {CAR (XII, AR:;STJ\CI(],
MI:M (Y] - ) ser [CAR (Xl, CAR [Y11,
X (NlL, NIL, NIL];, BIN) (CDR (Xl., CDR [YJ];
MI:M t~ [Yl] - )
X [CAR (Yl, NIL, NIL};,
MI:M (CIDR (Yll ->
Interpretatial: The LCOP construct evaluates its argument
Interpretation: This functioo saves the original values in a manner identical to the evaluation of t.~e clauses
, . of the atoms making up the formal argument list X on in a functicn body. Ho-tever, if all the arguments are
..J the argument stac.k: named ~ Simul taneOJSly t..'1e evaluated withC11t a conditional having been satisfied,
value of the formal ar9ument~
is set to the evaluaticn begins again witb the first argument.
corresponding elements of the actual arguments given
in the list Y.
6. CBN PBCGl [Xl, X2, ••• , xnl :-
alAL.PFO:il [F:JN.. [Xl1, LIST [X2, n, ... , xnI];
CiN ONBIND (Xl :-
A:II:H [Xl -> NlL;, crN eJ'NJ'RCXil [X, Y] : •
ONBIND [CDR [Xl], rox::M [Y] -> X;,
SF:!' [CAR [Xl, FOP [~l]; FJl:P-L [CAR cY]],
ElT.N:..PBCXil [X, CDR [yll i
Interpretation: This function restores the original
values of the atoms on the formal argument list X Interpretatioo: '!his func+"-..i.m successively fNaluates Xl,
stoc ed en J\RGS'.tP.CIt. X2, •••, xn and return the result of the evaluation of
Xl.
4. 03N CCND [Xl, X2, ••• , Xn) :-
91XJ::r:N.) [LIST [Xl, X2, ••• , Xt1] 1; 1. ClJ1 I:Rl.VER [] : • (Eval IllJLISP driver)
c
RI:S<- NIL,
CST FJlN.,CCNO [X, Y] : • WFS <- NIL,
Am'l [Xl - ) NIL;, EXm <- NlL,
Y ( - aiM., [e:.t\AR (XI I, REMXJI <- I~,
oor [Y] -> FJ1w::::r:N.) [CDR [X]];, '!ffiPRI [ 1,
F!JN.I!IXJ'L [Yt <:DM. [Xl] i ffi!Nl {'.$ -],
P.RINT (arM.. [RFJ\D []] 1;
Interpretatial: '!he a:ND funet:.icn successively ENaluates
the car of Xl, D, •••, Xn Until either a non-NIL In~e.rpretation: This is the default e'Tal-LISP driver
value is encountered or all have evaluated. to NIL. In functicn as primitively defined in machine language..
the former case the cdr of that argument is evaluated 'the function DRIVER is repeatedly evaluated by the
as a function body (see the interpretation of APPLY muLISP executive driver loc:p. 'lherefore IJt:UVm can be
for detalls). In the latter case NIL is returned by redefined at will to suit the user's needs. por
cam. ~is extended COW is a pa.ierful upw'ard instance the follQling is a sample ertaJ.-quote-LISP
canpatible extensicn of the CCN:) functicn described in driver:
original LISP l.S.

5. CBN LOOP [Xl, X2, ••• , xnl :-


ON I:JR..-vrn. {1 : • (Eval-quote muLI.SP driver) a
Rt:S <- NIL,
FJlN.LC1JP [LIST {Xl, X2, ••• , XnJ, WRS <- NlL,
LIS!' [Xl, X2, ••• , xnl]; EXm <- NlL,
ON FJlN.liXJP [X, Y, Z] :- . REMXJI <- •RF..N::X:H,
'IDU'RI £},
A:II:H (Yl - ) PR.INl ['-) -]t
f:.l N..1..tXJP [X, Xli, PRINT [~ [RF.J\D [], REN) [] 1] ;
MCM [C/;R [Y 11 m MI:M [e:.t\AR [yll -)
fYH.. [eM (Y}],'-
FJl N..l1:t:JP [X, CDR [Y]];,
Mai [CA.t\AR [yl] - )
Z ( - E1lJ4L [CAt'R (Y] I ,
NJr [Z] - ) EY m.J:t:Jp [X, COR [Y}];,
6lN..'2lJffl {Z, O)AR (Y] 1i,
FJlM.J3CDY [NIL, Ci'R cYll,
fYN.J.J:rJp [X, (1)R [Y 1] ;

V-30
(\)
V-29
Q. Environment Functions
P. Memory Kanagement Functions The environment functions are used to save and load muLISP
Tbe memory management function is used to force a garbage collection environments. Prior to saving a system, all the data spaces are
and return the amount of currently available data space. Since memory automatically compacted into one area of memory so the resulting SYS
management is fully automatic in muLISP, normally there is no need to file will be of minimum size. The SYS file can be loaded into a
explicitly use the function except for its value.. see section III for a different size comp.1ter system than the one that prcduced the SiS file.
di.so.lSsion of the memory mana9 ement system.
see section I-B for a detailed discussion on the use of SYS files.

1. CIN SAVE [X, Y] :-


1. aN Rro:AIM {] :- N:Jr N:1IL (WRS] ->
perfocn a qa.tbage collect.icn, write out .the final record of the current output
the amount of free space expressed in byteS;
sink and close the file,
Interprl!tation: This funetioo forces a ga1:bage collection WRS <- NIL,
to OCOJr. The total amount of free space in the atom, SAVE [X, Y] i ,
vector, and pointer spaces is returned, expressed in ~ (Xl A.~ ~ [Yl ->
bytes. Note that tva bytes are required for each NOLL [Yl ->
muLISl? pointer cell. Thus nodes require 4. bytes, <:aDpaCt all current data structures,
I save a memory image of the current envirooment
numbers. require 6 bytes, and names require 8 bytes.
In addition names and numbers require storage for
i· ~ as a SIS file named X on the o.u:rent drive, :J
their respective print name st.rin9 s and number TRiE; ,
ccmpact all current data. structures,
vectors. save a memory image of the o.u:rent envirooment as a
SiS file named X on drive Y,
'IroEi
NIL;
Interpretation: This function saves the current muLISP
environment on a disk file. Since the currently
l!d:ive data structures are cOtnpacted before the save,
the size of the SiS file is prCJIX)rtional to the a..tmber
of these structures in the system.

2. aN l'.-Q\D [X, Y] :-
Ni\ME [Xl AND ~ [Y] ->
NOLL [Y] - )
load the memory image SYS file named X from ()
the OJrrent disk, .
ros<- NIL,
retum dLtectly to the exeCutive driver loop;,
load the memory image S'!S file named X from drive I,
R)S <- NIL,
return directly to the exeaJtive driver loop;
NIL;

Interpretation: This function restores the muLIS?


environment present at the time of the SAVE. If the
SIS file is successfully loaded, l'.-Q\D does not re~u.m
a value tut jumps directly to the new exeoJtive driver
loop.

V-31
Section VI: The muSTAR AIDS

~
muLISP source files can be generated in one of two ways: either an
\' 3. ON S'iSTEH (] :- external editor or a resident LISP editor can be used. The text editor
. car.paet all data structures into 1011 memory, provided with your comPJter's disk operating system is an example of an
return to operating syste:n: exte.rna.l editor. Program development using an external editor consists
of iteratively editing, load.ing, and testing scurce files..
Interpretatim: When this function is e.xeoJted, all data
is compacted into. low memory and then control is The principal advantages of using an external editor are that
retw:ned to the operati.ng system. The comt,:aetion of usually the user is familiar with it and that comments can easily be
data allows for a re-entry into muLISl? with the same included as part of the text. Although an external editor is a
environment that was present at t.."1e ti.Ine of' the call perfectly satisfactoty method of program development, it is somewhat
to the function SiSI'E.~ The re-entry aCdress for O?/t-t slow a.rrl cumbersome, and not conducive to creative work. Repeated disk
versioos of muLI.SP is lOOH (hexadecimal). accesses are required to make even minor changes to function
definitions •

These problems are conveniently resolved in muLISP-80 with t...~e


introCuction of the muSTAR Artificial Intelligence DevelOfmeOt Sys+'~
mustl'\R greatly reduces program" development time aOO fully utilizes t.he
interactive nature of LISP. Using' the resident editor and tracing
) facilities provided by muSTAR, function definitions can be created,
teSted,' and througbly deb.1gged all within the system. This enccurages
the incremental a;;:proach·to program.mi.D; aro avoids the cumbersome edit.-
debug-reedit cycle.. Thus pr:ogram development moves much faster am is
definitely more enjoyable.

The remainder of this section will acquaint you with the use of
:. muSTAR AIDS: how to get into it, how to fully utilize the various
options available, arxi bow to use the text editing commands. Tr~ text
editing commands include cursor control, text display, and
insertion/deletion of text. The description in section VI-C of how
musrAR works will be of value to those users who wish to extend or
mcxli.fy it to suit their needs..

'!be muS'I'AR editor will work for virtually any mcdem CRI' te.t:ninal
running' at a high BAOD or data transfer rate. ~he only non-standard
features used by mUSI'AR are the characters which move the cursor up a
line and move the cursor to the oome position, or ~ left-r.,and comer
of the scree..'1. The distributed version is customized for the ADM-3A
te.rmi.naL If some other teminal is being' used, OJSt:.Omi:zed functions
will have to be. written to perform these functions, as described in
section VI-C below.

VT-'
.., ~ ....
A. !lain Menu Coumaands
u .
. , v EDrr VAR.IAm..E - This option is used to create and/or edit
a program variable's value. When activated. this option
is distributed as a muLISP S'iS fUe. Thus it can be loaded
Ir1IJS'!AR displays the following prompt::
by' either method described in section I-B of this manual. Probably tr.e VJ\R.Ill.m:.E Nt\ME (S) :
easiest way is to use the following CP/M level camsand: As many variable names as will fit on one line can then
be typed. After a carriage retum is entered. the system
A>fIJLISP KJSTAR will display the variable(s) and pretty-printed value(s)
with the o..trsor at the beginni'1g of the text. The editor
'l11is command will first load muLISP and display the logon prompt.. can then be used to modify the. text and the Value(s) of
Next the muSrAR system will be loaded and its executive driver will be the variable(s) can be reassi~
called. The driver will display the mUSTAR menu of opt:ioos ava.ilable to
the user. This is ~ menu as displayed on the console:
P EDIT PROPER:rY - This option is used to create and/or edit
OPrICNS: F mrr FON:TICN a name's property value. When activated. this oPtion
V mrr VARL\BL.E first displays the follOWing prompt::
p mIT l?roP~ Nt'\.."re:
E 'EN:\L LISP Chly one name is pennitted for: property edits; adiitionaJ.
Q EV1\L-QOOl'E LISP names will be ignored. After a carriage return is
'r TP..ACE FtN:TICN entered. the system will display the follOWing prompt:
o ~ FtN:TICN
~.

t,..; ~ .
R. RFJ\D FILE Again only one property indicator can be specified.
W WRl"!E FILE . After a carriage return is entered. the systeIll will
D SEI.a:r DRlVE display the variable name. indicator. and current
property value. After the edit, the lIlOdi.f~ed expression
C2l1 be reevaluated.
ENTER c:eolCE:

'11le facUities available in ~ fall into three eat.ag'ories, as 2. Debugging Pac~ities


reflected in the list above. 'I'he first three opti<XlS call the display-
oriented editor. The next four are used for program. debugging. The
last three· fall into the categox.y of disk. flle storage. B EVM. i:.J:sp - This option is used to initiate an eVal-USp
driver loop as described in se<:tion I-D. The prompt
When this menu is displayed, enterinq any of the valid option string -* - distinguishes it from the default muLlS?
cha.racters w1.U initiate the corresporx1i..nq facility as described below. prompt string -$ -. This eVal-LISP loop will continue
The system will only respond to valid option characters. An unwanted until an expressicn evaluates to the name .f:UL
cb:)ice can be aborted by simply typi.nq a carriage retum when t::le option
prompts the user for intUt.
Q o .EVAL-Q00l'E LISP - This option is used to initiate an E!7a.l-
quote-LISP driver. also described in section I-o. This
1. Editor Facilities eJCeo.ltive is" preferred for debugging by SOme. LISi? ~ers.
The prompt string is -~ -. This e"·al-quote-LIS? loop
P EDIT FmCTION - This opticn is used to create aOO/or edit . will continue until the function EX.Xr () is eJCeo.lted.
a muLISP function's I.AMEDA definition. When activated,
this optioo displays the followin; prompt:
FQtCrIal NA.HE(S) : T '!'RACE FUN::TION - This option is used to trace a LAMBDA
As many function names as will fit on one line can then or NLA.'1BDA defined function for debugging purposes.
be typed. After a carriage retum is entered, the system When activated, this option displays the follOWing
pranpt:
will display the definition(s) in pretty-printed form,
using indentation to highlight ~e structure of the ~~(S):
function definition(s). The cursor is [X)Siticned at t."le As many function names as will fit on one line can then
beginning of the text. The editor can then be used to be typed. follOWed by a carriage return., Whenever a
modify the text as described in VI-a below. Q1Ce editing traced function is Called. the function name and aCt:lJal
is completed and if tr..e use!' desires, t.be function (s) are arguments are diSPlayed. When Ithe funCtion returns,
redefined usi.ng the modified definition(s). both the function name and retumed value are displayed.

;...
V!-'
Indenting is used to highlight the nesting of function
~. B. Text Editing
The muSI2\R editor bas been specifically designed to facilitate t..~e
o OHTR...\CE PUNCrIOB - Tbis option is used to untrace or editing of muLISP functions. It is a screen-oriented LISP editor, which
restore the definition of a traced function to the continuously displays a "window· or "picture" of the text making up a
original definition. Tbe same prompt as
for the TRACE function's definition. Thus the user can make changes and see the
FUNCTION is displayed, calling for a sequence of resul ts instantly.
func..uoos to be entered by the user for untracing.
Because mu5TAR is written entirely in muLISP, the user can e.xterd
the system to his/her own taste. BasicaJ.!ly each ASCII control cha.raete.r
3'. Disk I/O Facilities is a function which can be redefined at will to perform. wha~/er task is
desired. This ,is more fully explained in section VI-c.
a R.!N) J?ILE ~ This option is used to read muLISP source
files. When activated, this option displays the Function and' variable names used in muSTAR which might conflict:
following prompt: . with user program na:nes are terminated with a .$....
In order to avoid
F'ILE Nt'\KE.: such conflicts it is advisable to avoid using such names in user
After a name ai:ld a carriage retum is entered, an attempt programs.
is made to open the file with the given name of type LIS.
for input and read it into the system.. If the file is The general principle for using the ItUJST.AR editor can be described
not: fOWld the following message wlll be displayed and iJ in two s-~ps: first, move tbe Olrsor to where YOJ. want to edit; second,
then you will be re-prompted for a file name: insert, delete, or cha.t:¥;e the text at that ~int. The best w"¥ to learn
F'ILE lDr PaJro yoo.r way around the system is. to experiment. with some simple fun::+-~cn
Files generated by either musrAR or an external editor definitioos •
can be loaded in this way. For files made externally,
the last statement of t:c.e file should' be a call to the
function ~ to return control to m~ Also the 1. Cursor Control
function DRIVER sbould not be modified by the source
file. '!be cursor control commands are used to ~1tiCXl the OlrSOr at the
point where the desired change is to be made in the text. The cursor
(the block or line of light that shows where the next character will
• W'RITE PILE - This option is used t.o generate a muLISP ~ when typed) is manit;ulated mainly by directions entered with the
source file. When activated, this option displays the left hand on the keyboard. On most terminals control characters are
follcwi.r:q pranpt: entered by depressing the control key, usually marKed c:EIu ar:d typing
PILB NNm: the desired lette.r while the control key ·is still depressed.
After a name and a carriage retum is entered, a new disk
file with the. given name of type Lm is created.. A '!be basic cu.rsor contJ:ols are oriented in the shape of a plus sign
sequence of ftlD:tion definitions and/or variable values so that en standard keyboanis the l:X'Sitioo of the. key corresp:nis to t..~
and properties is written to the file in pretty-pri..'"lted \) direction the cursor is to move. This is illustrated by the following
. foen. The functions which are written are these en the d.iagram:
property list of the file name under the indicator
Em,C' IONS. The variables and/or property values which
get written to the file are those of the names on the up 1 line
property list of the file name under the indicator
These property values themselves are also
YJ;,..'QJABLES.
written to the file so they will automatically be read
tE
back for future muSTAR edits. Note that when the
development phase is complete, files produced by muSTAR A S D p
can be read by the muLISP system alone. -E- -E- ~ ~
left 1 word left 1 letter right 1 letter right 1 word
D SELECT DI5X. - This option is used to select the disk drive x
to be used in subsequent disk file accesses. U'ltil t.lUs
option is used to change the drive, t...'"le current default ~
. drive is used. down 1 line

VI-4 ':~~
relatively speaking, scrolls the text DOWN one line.. When scrolling,
the OJrsor re.mai..ns at the same pJsition in the text, moving up or dawn
with the text. However, if t.'1e cursor reaches t.~ top or bottom of the
In the diagram above, the direction and length of the arrows scx:een, it remains there. The cursor never leaves the screen.
indicate the direction and relative magnitude of cursor motion caused by
t:..~e associated 'command. The best way to get the "f~-l· of the c:ommarrls C1".RL-C is used to move the window down a screenful (i.e. to display
is to experiment with actual t:ext. the next 18 lines on a 24 line screen). CTRL-a does the inverse
operation of moving the window up a full screen.
o:RL-D moves the OJrsor one character to the right, CT.RL-S moves it
one character to the left. (Note that the latter command has the same '!be display control commands are deactivated if there is no moce
effect as typing a CT.RL-B or backspace). Amplifying this left-right text in the direction of wi.rx:low motion.
movement, cnu:rP mO'\1e5 the cursor one word to the right, CTRL-A moves
it one word to the left. Both of these commands will leave the OJrsor
at the beginning of a word. 3. Enterin9 -;ext
In muSTAR a vord is defined to be a muLISP name in the text or a The.re are two modes for entering text. ~ v is a toggle ·switch"
delimiter such as a parenthesis or period. Note that for these four used to switch between mo:ies. In either mode te:tt is inserted by simply
commands, tbe text on the screen should be t...~ht of as one long string typing it in.
of text. Thus- the cursor is automatically advanced to tbe next line
when t.'1e end of the current line is reac.oed. Alternatively, after the Initially, when the toggle switch is OFF, the editor is in t..'1e
begir.ning of a line is reached when backspacing, the cursor will move 'to non-~ mode. AIr:! existing text on a line ·tlill k:>e overwritten by new
the erxl of the previous line. text being entered. This is the easiest way to enter text initially.
Mistakes can be corrected by simply typing over them with the
Entering a crm:.-E will move t:be cursor up one line.. A C!'m"..-X will oj corr:ectioos. The st,:aee bar wi l l -erase- c.baracte.rs.
move it down a line. After the cursor is moved to the new line by
either of these commands, it is automatically advanced to the next word When a CTRL-V has been typed, mu~ is in the mSERT mode.
on the line. Typing a linefeed or c.rmrJ will move the cursor to the Qlaract.ers ani spaces that are typed are actually inserted in front of
begi.nni.rq of the next line. the remaining characters on the line, if any. The characters to t..-""e
right of the i.nserted charaC""'~s will be p..1Shed aver to the right. As a
To move to the begim.i.nc1 of· a line, the command is c::r.RL-Q. To move step-by-step example, the text -(CONS BETA.)" can be modified to read
in the opposite direction, to the very end of a line (after the last -(CONS ALPHA BETA)· by inserting -ALPHA- before -a.E:rA". In the INSE:R:r
cha.r~), type aIlL-B. mode, this insertion would appear 00 the console as follows, where the
A carriage retum (i.e.. a ~K) typed when in the rxn-INSERr moo.e
underscore indicates the cursor p:)Sitiat:
(see section B-3 below) advances the cursor to the beginning of the next
(alS s;:.TA)
line. A new line is added if at the bottom of the current text. See
sectioo. B-3 for the effect of catriage. returns when in the IN5E2r JtOde. (a:NS ~)
(cas Ataf.TA)
0siD; a'l1y the alrsor control co~, the alrsor can not ~ moved (a:NS~)
to places on the screen that are not characters in the text.. -ro move (a:NS~)
(CCNS~~)
the cursor past the end of the current line or past:: the last line of
text, use spaces and/or carriage returns to inSert new text instead of (a:NS ALPSA s;:.TA)
usiD; the Olrsor control cha.raet~s. \)
When muST.AR is in the insert text mode, carriage returns (i.e.
CI'BL-K) cause new lines to be inserted in the text..
The OJrsor will end
2. Display Control up immediately following the new line. See section B-1 above foe t'-'1e
effect of carriage returns entered in the Ncn-INSmr mode.. Entering a
When 100g or multiple definitioos are displayed on the Ott screen, a.RL-N will always insert a new blank line in the text; however, the
only part of the text can be visible at anyone time. Tbe text can be
t..'1ought of as being -Written" on a long SCtoll. The CRr scr~ is then OJI:sor will end up on t..'1e new line..
a -WiOOow· on the text, which shows only a J:X)rtion of the scroll. Since CTRL-P is the escape control chara~ter used to make delimiter
our window, the CRT, can not move, muST.AR scrolls the text up (toward characters be used as names instead of delimiters. To use spaces,
the endof the text) or down (toward the beginning of the text). Thus parent..'1e.se5, periods, arxi brackets as names simply type a CTRL-P before
moving the text up or down is called -scrolling". .
typing the delimiter character.
To see the next line of text, typing ~ z moves the window tx:)WN ·a
line or, relatively speaking, scrolls the text OP a line. To see the .
previous line of text, typing a CTRL-W moves tbe wir.co'W UP one line or, VI-7

VT-f;.
Normally the "E- option is choosen since it evaluates the text
which has been edited. The -A- option abandons the text and does not.
evaluate the text. In case CTRL-K was typed inadvertently, the "e"
•• Deleting Text option can be ,used to return to the edit.
\
'!bet:e are .fou~ ways to delete text:

1) In the Non-Insert mode, simply type spaces or new 7• Coamaand SUDDDary Table
characters over. tQe text to be deleted;
2) To delete the character that the cursor is on, type Control
C%.1?L-G; Q1aracter Function
3) To delete the word to the right of the cursor, type A Move OJrsor left one word
cr.RCr'r. . B Move,cursor to em of Olrrent line
C SCroll text lID a screenful
4) The cvrrent line can be deleted by typing e.tmry. o 0- ~ve Olrsor right one c.~aete!"
E li:JVe cursor UD one line
A word ot:_cautioo: since the letter Y is so easy to hit by mistake F Move cursor right one word
when reaching for a T, it is advisable to use extra care when deleting G Delete o.u:re.nt character
words, since a long reach can eliminate an entire line. It is also a H Move cursor left one character
good idea to use ~ y with discretion since repeating the ~ I musm
command will -walk- you down the line. This often al.lows the user to J ~e OJrsor down one line following le.adi.D; blanks (LI:NEFEm)
-recycJ.e- words into a new line. '-' It Exit editor car.mand
L Repeat last search cemmaOO .
K ~e OU"sor dcwn one line to begi.nni.ng of line (RE:roRN)
s. Finding Baaes N Insert a blank line
o Find a name
'the ability to sea.tch for a muLISP name in text is the functioo. of P Escape character used to enter delimiters as naxnes
these command$. ~ displays the following prompt on the top line of
the screen:
o ~e to begi..nning of current line
R SCroll text down a screenful
nm~ Move OJrsor left one character
S
T . Delete word to the right of cursor
The user can then enter a name, terminated by a carriage return. o ONJSED
The cursor will then move to the next occurrence of the name in the V Toggle .insert mode switch
text. cnly the text actually on the screen is searched, and if the name W SCroll text down one line
is not found the search will begin again at the top of the screen.. If X ~ Olrsor down one line
the name is still not found, the' cursor ww. erxi up advanced one word to
Y Delete Olrrent line
the right of its original ~iticn.! . SCroll text up ooe line
Z
To search for the next occurrence of the same name given the last
time C'!mrO was used, type <:mI.t-L. ()

6. Exiting Editor

When the edit of a variable, function, or property is completed,


typin<; a Ct'.RL-« will cause the follow in9' menu to be displayed on the
. console:

OPl'ICNS: E ~ TE:<.T
A ABAN:x:N nxr
C a:Nr1NJE mIT

~ O3OICE:
VI-9

:"~
VI-R
2. The muSTAR Executive
c. Custom.izi.n9 lIluSTAll
The e.xeoJtive is a ver;y simple loop which displays the main option
\ menu and then calls a function to perform the requested option. On the
1. Console CustomizatioD property of each option character, under the indicator r:<;:etrrIy'E, is the
LAMBDA body evaluated when the respective option is chosen. The
All musrAR users except those own.ing ADM-3A te.cninals will probably function ~ is used to display a prompt and i.npJ.t the response.. It
have to write a simple muLISP library file containing functions for returns a list of expressions entered by ~ user.
movinq the cursor up a line and for moving the cursor to the home
l,X)Sition (the uwer left corner of the screen). The muSTAR function .Ill: If an editor option was chosen, this list is passed to the
~ is used to move the OJrsor to the begi.nning of the OJrrent line ar..d 5-expression-to-text translator. Here the expression is converted to
up a given number of lines. If no argument is given, it still moves the the internal text data structure as described in t..~ next ~icn..
cursor up one jline. Tbe function .B.Q.t:1ll moves the cursor to the upper The editor is then called to pretty-print and permit editing of t..~e
left-hand corner of the screen without erasing the screen. It also text. When the edit is complete and the user desires to evaluate t...~e
includes a 1'ERPRI to reset the muLISP cursor position counter. 'the text, the text-to-S-expression translator is called to translate the
following are the d~ault definitions of these functions: text and evaluate the result. If parentheses are Wlbalanced or t:..~e
continue option is chosen, the editor is called again so the edit can
(DmJN OP-LINS (IJ\MBCA (NJM) continue.
«Zmli' ~»
(PRINl CR) '!'be trace aOO tmtrace options pass the list of names entered by tr.e
(I£XJP
. (PRIm. tJPI..INE)
(SED:) tui (SUBl K:H»
o user to. ~ and ONI?ACE func+-....ions respectively. A fpnction is traced
by redefining it to call the function f;VTEACZ. ThUs when a traced
function is called, it calls EVTRACE which prints its arguments,
«IDr (PWSP NJM») ) » ~uates th~ or~~inal function, and then prints the' tesult.m; value..

(DEFtlN BCM:S (I.AMB:lA () The write file option opens a file for output on drive *DR.I\TE*.
(PRINl HOME) (TERPRI) (PRINl BJME) ) ) First it prints the basic functions needed to read-in the remaird.er of
the file (i.e. OEFUN, SZTQQ, PO'I'OQ, and FLAGOO). Then a list of
(~P~24), , N.mber of lines (Xl CRr , functions and variables in the file are printed. Finally the pretty-
(SE!'CXl LIN-I.m$ 78) , N..m:ber of columns - 2 , printed function definitions, name values, and property values are
, c.rm:..- lE hex ,
printed. If a function which is being saved bas been traced, the
(~ ec:ME .~.) A •
original definition and not the traced version is saved.
(sr:.tW OPLINE .~.) , CXRL-!t • OB hex ,
e , crm:rM. • CD hex ,
(SE!'CXl CR • ri )
(:r05) 3. 'text Data Structure
Note that the wAw notation used in the last lines of the above It is a relatively simple matter for an experienced muLISP
l.ist:in; means that an actual control character is to be inserted in the programmer to add features to the editor to suit his/her tastes.
text file between the two double quote signs. It also may be necessary
to adjust for your console's page and lice lengths.
o Qlan;es which can be made include mcdi.-oFying the effect of centrol keys
and taking advantage of special CRT features. The first step is to
becooe t...~crou9hly familar with how the text is stored and codified.
To cust.omi.%e muSTAR for you.r tecninal, first use
external editor
a;1
'l1len the aLready existing ooildin<; blocks in t:re system for manipulating
to make a file of type .L.m. using the definitions above as a mod.el. Note the text can be combined to achieve the desired effect.
that the call to the function ROS at the end of the file must be
included to make the console the current input source. Immediately The text currently on the screen at any given time is stored as a
after loading MtJS'TARSlS as descriOOd in section VI-A above, c.bcx)s.e t."le list bound to the glooal variable ~ Except for the first el~ent:
"R' option and read in yoor custom.i%ation file.. The c:ustorni%ed version of *TEXT* which is alvays NIL, each element of this list represent.s a
of muSTAR sbould then be saved as a SYS file, using a new name to line of text. The global variable PA<ctEtiS is set to the maximum
distinguish it from the uncustomized version. To accomplish this, allowable number of lines on the CRT screen. Its default value is 24.
select the eval-LISP T' opticn and then tnake t:.~e following comma.nd: . '!bus the length of the list '*TIXT'* can never be greater t.."'.an PAG-L.E:-:$.
(SAVE MISTAR) Each line or row of text (i.e. element of *TEXT'*) is a list
specifying the text on t.'1at row. The fi.rst element of a row is always a
This will create a disk file named MYSTAR.SYS. Thereafter non-negative integer which gives the number of leading blanks, or
initiating muST.AR is si..'tlply a matte!: of loading MYSTAR instead of MUsrJ\R
as described in the introeuction to sec-~a1 VI-A.
.) VI-ll
VI-10
moves the cursor ar..d text pointers one token to the left.. Eac...'1 of these
func-~ons is dOC'JJ11ented by the description given in section VI-B above.
Altering the definition of these functions is the easiest way to
initial spaces, on the line. The remaining elements of the list. are customize mus.J:AR. There is a very complete set of existing primitives
called tokens. Tokens represent either the muLISP delimiters or names in the muSI1\R source. The p.1rpose of each should be ~e.nt from the
making up the text being expressed. The four possible delimiters are function name..
shown here enclosed in .double quotes:

\.(. .). • • .
• •
These four delimiters are stored as names on the list. In
contrast, tokens which represent names appear as sublists on the row
list. Generally the sublist is a single-element list wfx:)se element is
the name in question. Only if the cursor is -inside· a name (i.e. t:.he
cursor is p::>siticned after the fi.tst character) will a r..ame be unpack.ed
or -exploded" into the c.~ters making up the name using the fW'lCtion
ImPaas. When the Olrsor leaves the name, the cr~ac+--e.t:S are re:-...acked
cr ·compressed- into a new name using the function ~

At any 9iven time,· the value of the global variable. *ROW* is


a sublist of *'I'EXT*. The second el~ent (i.e. the CADa) of this sublist
is the row of text which the cursor is currently on. ThiS is the reason
the first element of ~ is the dummy row NIL. Amalq othel: t.h.i.ngs, 'J
being one row above, or ahead, of the current row is convenient for ..
deleting the OJ.rrent raw from ~ usi.ng RPLACD.

'l'be current {X)SitiCX1 of the cursor in the current row is determ..ined


by the glcbal variable *CCI..*. It is always a sublist of the cun:ent tOW
of text.. For the saJ:1e sort of reasons' as for *RCW*, the sublist
begins one token to the left, or ahead, of the o.u:rent token.
Note that
the cursor is never to the left of a line's leading blanks. ThUs *COL*
can ~ be ahead of the OJrrent token. I
Lines of text which have ~ scrolled off the top or bottom of the
screen are stored as lists under the variables *PRE-T.EXT* and *POST-
~ respectively. 'l1Jese two lists are best thought of as st:aeks. 'the
line of text which is immediately adjacent to the current ·window· is
the top element of the stadt. 'thus the rows makin;} up *PRE~ are in
reverse order. A raw can be pushed ·onto *PRE-TE:cr'* or * ~ only
if there is insufficient room. <Xl the screen to store ~ row.
()
-I. 'text Prim).tives
When t."1e text editor is runni.nq, console i.npJt is in the raw i.npJ.t
mode as described in t.."le reader control variable P:>I:tioo of section V-M.,.
An input character can either be a delimiter, a normal printable
characte-r, or a control character. A delimiter: or printable character
is tn2!de part of the OJrrent row of text in accordance with the structure
defined above for storing text. If the control variable *rnSERT" is
non-NIL, the charaete.r is added to the text instead of overw'rit.ing old
text.
Each control character has as its value an ali~s name. Fer
example, t:..~e value of control A is C'!BIcA. The otber control cha.ract.&s
have analogous aliases. The definition of the respective alias is
evaluated when a control c.~acter is entered. '!bus the funct.ion ~
Appendix A: Backus-Naur Form
Appendix B: How to Copy the Kaster Diskette

- .BackUS-Naur Form (BNF) e:zuatiQ1S prOU'i.de a st:ar..da.rd corwentioo used


to formally define the syntax of a language. Within a 8NF equation a As soon as possible after receipt of the master diskette sut=P1ied
character string immediately preceded by a -<.. and followed by a")" by The Soft warehouse, make a working copy of the diskette. The
denotes the class of objects named by the string•. A character st:ing follOli.ng infocnation is prov-ided as a guide for those who are not yet
. not .so delimited stands for the string' itself. Note the contrast familac enough with their computer's disk operating system to make a
betw'een this and the conventional practice of quoting strings whic.~ copy of a diskette. Since there are many different operating systems
stand for themselves and not quotin<; strings which are names of ecjects. and computer configurations, this discussion can only be a general
guide.
A BNF equation defines the set of syntatic objects belonging to a
particular categ9f:y of the language's syntax. '!be symbol -::-- is used L Study the documentatioo SJt=Plied with the comp.lter·s,
as an abbreviation for the pbrase -is a- and the vertical bar -,- is disk operating 'system. Most cases of accidental erasure of the
short for ~or·. A BNF definition of numerals may be specified as masteJ: diskette or ot..""er irrecoverable errors are can.mitted in
fallGls: the first few moments by overly anxious and inexperienced
users.
<numeral> ::- <digit> I <digit> <numeral>
<digit> ::- 0 I 1 J 2 I 3 I 4 I 5 ( 6 I 7 I 8 I 9 2. Obtain an appropriate number of blank higb-qua.lit::y
, diskettes suitable for yoor drive.
As in tbi.s example, reoJ.rsive definitial is fr~uently used in BNF
. e:;:uaticns. Also note bOIl juxtaposit::i.cn of c:a.tegory names denotes the
ccO:~ cax::atena.t:icn of the c:bjects within these categories.
3. Become thoroughly familiar w itb. the terminal,
computer, disk drives, and operating system. o
Backus-Naur Form. is defined in the -XJ.;OL 60 Report. Revised Report 4. Practice initializin; a diskette, then transferrin; a
<XlAlgorithm Lanquage ALGOL 60·, Communicatigns J2f~.!.Q1, Volume 0, disk operating system. to the initialized diskette. Generate
Jamary 1963. the largest versi<n of the ~at:i.n; syste11 tbat yoor COtnP-lte.r
is ca.;;able of supportinq.

S. Practice transferring to the DellI diskette files fran a


spare, write-protected diskette.
6. For operating systems with a diskcopy utility, use
this method to copf the master diskette since it is de£initely
the easiest and fastest Wiq to do so. Make absolutely sure the
drive with the master is the soo.ree and lI:Zt the destinaticn for
the copf canmatXil
7. For multiple drive syste!DS, the follcwing CP/M PIP
(Peripheral Interchange Program) command l wi l l copy all files
frem drive A to drive B: ()
PIP B:-A:*.*

~e 6iU1valent ccmna.nd for Craneoco ax:s users is:

.~,
XFER B:t:::A:*. *

8. Copying diskettes is much more laborious on systems


having only one drive. Generally, it involves repetitively
reading a portion into RAM memory frc:n' t.he source disk,
S\i itching disks, then writing t..'1e tx'rtim onto t...~e destinaticn
disk. This is repeated until t.he entire source disk has been
copied. The process generally involves using the CP/M DDT
utilit:J pro;ram ~ a resident monitor in read-only memoty.
JI_'
Appendix C: Xmplementing Machine Lan9uage Subroutines
9. If the above met.~ods are unsuccessful because your
disk drive is unable to read the master diskette and ycu. have a
mul tiple drive system, try readinq the master on different Some specialized muLISP applications may require the writing of
drives. '!be master is recorded on a high qUality diskette by a. machine language routines. For instance a user may wish to enhance
precisely adjusted drive.. BGiever, there are inevitably slight muLISP with graphics capability, or perhaps it is necessary to hand
mechanical and electrical differences between various drives compile a pa..r+"~cula.rly critical function for efficiency reasons..
and diskettes.
. Address typing is used by muLISP to determine a function's ~lPe.
10. If your system is still unable to read the master 'this necessitates the beginnir¥:1 of all mach.ine language subroutines in
diskette, then: low memory. A dUMIilY jUI:lp table, beqinning at location 01038 (hexa-
deciI:1al), has been set aside for. jumps from low memory to user cefined
a) Cleek to see whether the Ptcp!r type of diskette rout.L'1e5. There is sufficient room for four (4) JMP inst.roetions (Le.
was specified when yOJ. placed ycm: order. opcode C3B). These jump instructions can be altered t.o jump to t~e
address of the user defined routine wherever they are located.
b) Get help fran an experienced professiaal. Depending on your system, additional room for jumps might be found in
unused areas in page zero of memory.
;c) Make sure your drives are correctly aligned, and
1£. not,. have them prafessicna.Uy aligned. Since muLISP uses all available memory below the DOS (disk .-1
operating system), the best place to locate user defined routines is in -._.1

t d) COntact directly the s~ie.r fran whaD. the system the -protected- memory above the DOS. Of course this mandates
was PJ.rcb.ased. generating a DOS slightly smaller than what yt::X.1r CO%Irf;Ute.r: is nonnally
capable of supporting. Another alternative is to change the JM.F
instruction at location ooosa to an address less than its current.
a::Xiress thereby "fooling- muLISP into believing it is operating u.'1der a
smaller I:)()S. Of ccurse another JMP instruction will have to be placed
at the new ~ress to jump to the I:)()S. This will free some memory just
below t.he DOS.

All user defined subroutines will be CBV, spread functions of at


most three arguments (see section V-o). If more than three arguments
are required, they can be passed in as a list. The addresses of
arguments are passed to machine language routines in the register pai.rs.
'-be first argwrent is in the HL r~ister, the second in the DE registe:-,
mld the third in the OC register.

'l't> return control to muLISP simply ter:ninate all routines with a


RET instructio.,. . The returned value of the function ~i11 be t.he cata .~
structured poi!1.ted to by the HI. register pair. It must be the address .J

of a ba1a fide muLISP data object '(see section II). Even if no special
value is desirad to be returned, EL should still b~ set to some value
such as NIL. The value of NIL can be determined by disassembling the
machine language definition of the funC+-~a1 WLL.

Linkage to,machine language routines is done thrcugh the use of t...~


muLISP function PUT!). For instance, evaluation of the folloW'ing
expression will define the function FCO to be a routine which begins at.
location Ol03H:

(PO'lD (QOJIE FCC) 259)

The function GETD can be used to find the starting address of


pri.:nitively defir.ed muLISP subrou.ti.nes (see secticn V-01. Kr.o'W ing t..1ese
addresses, user defined subrout.ines can call the primitive subrouti.~es
dir~-ly.

1':-3
Appendix E: Punction Index

~~ <;ateoocr GmU2. ~
Appendix D: LISP Bibliography CBN AN:) Logical F-2 8
CfN APPLY FNaluator 0-3 21
erN AS:IX. Property B-1 11
Allen, J. R., Anatqny!Jf. LI.S2.t aN A1tM Recognizer 0-3 5
McX:irar-Bill Book Ca:n:pa.ny, NEw York, NY, 1978. selector A 1,2
CZV CXxxR
CBN CCN> Evaluator 0-4 29
CIN CCNS Construc+--..or B-1 3
Berkeley, E. C., and BdJrGl, O. G., (eds), Numerical Ir3 16
ON DIFF~
~ p"'o;rarI'Qj.m !Qnguage LI.S.2:.. n.s. Cp:ratim ADd. P;&licaticns, N.m1e.rical Ir7 16
ON DIVIDE
'nle M.I.T. Press, cambridge, ~ 1964. EYaluation 0-7 30
a:N DRIVER
CiN m <:cmparator E-l 6
<:::iN a:uAL <:anpa.rator E-2 6
~~ small SYstems \IQJrnal, LISP Issue, Vol 4, No 8, 0-2 1:1
CiN FNM, Evaluator
BrIE Publicatioos Inc., Peterborcu9~ NS, August 1979. 0-8 5
aN ~ P.eco;nizer
CIN ~ Flag I-2 12
BeDderscn, P., Fupctic;n Prcgranmjng; pPQ1icatiro.mxl Imp1e:rentatiCD,
Prentice-Ball, Enc;l&locxi Cliffs, N1, 1.980.
faN F'UsGP
c:::iN GET
c:z.J GEID
Flag
Pr~
Definition
I-l
H-2
J-l
12
11
13
o
aN GRfA.'l"ERP eanparatox: E-4 6
ON ~ SUb-atanic K-3 15
rtiEdnan, D. P.,~ L.i..ttJJ:. r,TSPf:r,
C!N LESSl? Ccmpa.rator £-5 7
SCience Research Associates Inc." N-6 23
. L~a1, Enc;land, 1974. ON~ Printer
CSN LIST eon.sttuetox: B-2 3
ON ~ System. 0-2 32
McCarthy, J., Recursive ~ops Z ~iC =r§sjoo:s CBN LCXP Evaluator o-s 29
ON·~ Cocparator £-3 6
.mi ~ ~QIPJtaticn .bY ~c:hioe,
NJmerical L-l 16
CoIm. }Ot, pages 184-195, /4pril 1960. cz<l MINJS
CIN M.INJSP P.eco;nizer D-6 5
'ON" MOVD Definitioo J-3 13
aN NAME Recognizer 0-1 5
McCarthy, J., et al., LI.SZ L.S. prcgrs:nrner l S l$!nrgl1,
c:::iN N:CN: Modifier C-3 4
1be M.I.T. Press, Cambridge, ~ 1963. 8
CIN NJI' . 1J:'gical F-l
erN WLL Recognizer 1>-4 5
c::IN ~ Recognizer 0-2 5
Maurer, W. D., A Prt;gtagmerls Tntr~~m.tQLJ:S2.,
;'.meric:an Elsevl.er, New York, Ni:, 1.973. CfN CBLIST ConstrJ,CtOr B-4 3 ()
CBN OR U>gical F-3 8
CJN CJf\DERP Comparator £-6 7
SUb-atomic K-1 14
Siklossy, L., ~ xa.JJs. LI.S2.t ON PAC$.
16
Prentice-Hall, t)')g.l&locd Cliffs, NJ', 1976. ON PIDS NJme.rical L-2
ON PLOSP Becognizer D-5 5
CBN fOP Assignment G-3 10
Weissnan, C., .LIS:e l...S.. Primer, ON PR!NI' printer N-2 21
aN PR!Nl Printer N-3 22
Dickensoo Publi.sh.i.nq Co., Belma1t, CA. 1968. 30
CBN p~ Evaluator 0-6
<::a"1 roSB .Assignment G-4 10
Winsta1, P. H., Artificial Intel' igenc e , CJN ro.r Property B-3 11
kXlisoo-Wesley Publishi.ng Co., Rea.di.n;, MAt 1977. C:iN rom De.f ini ticn J-2 13

'~)
h-6
Appendix P: Concept Index

AIDS I-1 features I-I


~~ categoey ~~ AU. Spaces Ex.hausted. IU-2 file backup V-21
argument stz\cK V-29 flag functions V-12
am r;}.JOrE Evaluator 0-1 Z1 assignment functioos V-9 flags II-l
ON Qt:JC7l'Im.r Nume.t'ical L-5 16 association list V-ll focoal arguments V-25
csv PJ\DIX Printer/Reader N-7
Reader . M-2
23
17
atan space llI-l function l:>ody V-2S
CJN RATCM auto-quoting I-4, II;-l function cell II-2
ON PDS Reader 1+-1 17 auxiliary funetioos V-l
aN READ Reader M-3 18 qa.i:bage collection III-l,V-3
ON REAJ.X:H Reader K-4 19 Backus-Naur FOOD A-l generic ordering V-7
C'!N R:.X:IAIM Storage P-l 31 bi.na..'Cy trees , II-3
CJ:N RE:'-'~ER ~"Umerical Ir6 16 break characters V-17 implied CCN) I-5
CIN ~ Flag I-3 12 insert mcde VI-7
erN ~roP Property H-4 11 call by name (CBN) v-25 interaction cycle I-3
CiN ~ Constructor B-3 3 call by value (CBV) V-25 interrupt: I-6
ClN RPI,;;CA Mcxiifier C-l 4 car cell II-1 iterative V-26
ON PJ?LAO) MOdifier C-2 4 cdr cell II-1
c::rN SA.VE System 0-1 32 closed t:oi.nt:at universe n-l I:.AMIDA defini tim V-25 r;
~
C3l SEr Assignment G-l 9 ~ts V-19 leading blanks VI-ll
C6N sr:ro Assigrment G-2 9 ~on III-l library files 1-2
ON SPACES ,Printer N-5 22 canparator fuD:tioos V-6 line edit IOOde V-20
CJN SY~. Env'i.ror.1men~ Q-3 33 ox:piling V-13 line edi ti.ng 1-3
ON ~ Printer N-4 22 constructor fuD:tions V-3 linelength V-23
CIN TIMES ~cal L-4 16 Continue option I-6 linke:i list 1I-3
CIN ONPAClt SUb-ataDic 1:-2 14 OJrrent inpJ.t soo.rce V-17 . local variable I-5, V-9
ON WPS Printer N-l 21 current outp.1t sink V-21 logical functions v-a
~ Recognizer '0-7 5 logon message I-3
• ON
D-<:o1e V-13 lower case coo.versial V-24
data cbjects II-l
data space boundaries In-2 machine language subr A-4
data space partitioo III-l master diskette !-2, A-2
data structures II-l rre:oo ry tlanagenent nI-1, V-31
d~iling V-13 men:>ry trap nI-2
definition functions V-13 meta-language r;-l
dist.illed code V-13 meta-semantics IV-l
dot notation meta-syntax 'N-l
dotted pairs
II-3
II-3 modifier functioos V-4 Cl
driver loop 1-3
name list V-3
eOo V-20, V-24 names . II-1
end-of-flle (EIF) V-19 No Disk Space V-23
envircnment I-7 no-spread function V-25
enviror:ment functions V-32 nodes ll-3
error diagnostics I-7 non-recursive loops I-5
error traps I-7, III-2 ntmber vector II-2
ev-al-LISP !-3, V-30 nuIIOer vector cell II-2
eval-quote-LISP I-4, '1-30 rn.mt>ers II-2
evaluation func-~cns V-25 numerical functions I
V- 16
e.xec:Jtive driver loop I-3
ExeoJtive option I-6 object list V-3
extended CCN:) I -5, V-29 outpJt pause I-7
external editor VI-l
'File: MOSTAR.LIB 08/12/80 The Soft Warehouse
(PROGl ••
p)1nter cells II-l (LOOP «EO (EVAL (READ» STOP» )
pointer space I11-1 (DRIVER) )
predicate V-25
pretty-print VI-2 \* •• *********** 0 TIL I T Y ROO TIN E S ***************\
primitive functions V-l
print na:ne cell II-2 (POTD DEFUN {QUOTE (NLAMBDA (rUNe EXP)
print name string I1-2 «EQUAL (GETD FONe) EXP»
printer control ( «NULL (GETD FUNe»)
variables V-24 (PRINI -*** REDEFINING .)
printer functions ' V-21 (PRINT FUNe) )
properties ' II-l (Pom FUNe EXP)
property functions V-ll FCNC }) )
property list V-ll
property list cell II-l (DEFUN SETQO (NLAMBOA (NAME EXP)
(SET NAME EXP)
quoted strings V-19, V-24 NAME »
radix base V-23 {DEFON PUTQQ (NLAMBDA (NAME ATM EXP)
ra!tt1 i..nt:u t mode V-20. (POT NAME ATM EXP)
reader control
NAME »
variables V-20
reader functions
real time Si~eI1S
V-17
III-2
(DEFUN FLAGQO (NLAMBDA (NAME m)
(FLAG NAME ATM)
reallocation III-2
NAME »
recognizer funetialS V-5
resident editor VI-l
'Restart option I~
(DEFUN PACX$ (LA.'1BDA (TOKEN) .
selector functions V-l
( (NULL (CDR 'tOKEN»
separator characters V-17 TOKEN }
(~ONS (PACK TOK~~» )}
side-effects V-4, V-9
sign cell . II-2
spread function V-25 (DEFON UNPACKS (LAMBDA (TOKEN)
stack space nI-l <COR (CDR TOKEN) (EO (LENGTH (CAR TOKEN» 1»
TOKEN)
sub-atcmic functions v-14
supe.r-parentheses V-18 (UNPACK (CAR TOKEN» »
S'YS file I-7, V-32
Syste:n optial I-6 (DEFOO ROes {LAMBDA (LST TAIL)
(LOOP
tasks V-25 «EQ (CDR LST) TAIL)
thrash.i.n; III-2 LST )
token V-17, VI-12 (POP LST) ) »
trac.i.n; facilities vr-l {DEFON CHOPS (LAMBDA (LST)
translator VI-ll
truth values v-a (LOOP
({NULL (COOR LST»
ua?& case conversion V-20'
(FROGl (CADR LST) (RPLACD LST NIL) )
(POP LST) ) »
value cell II-l (DEFUN SPLITS (LAMBDA (LST NOM)
vector space III-l
{LOOP
varn.ing messages I-7 «ATOM LST) NIL}
(SETQ NOM {SU'R 1 NT1M"
word VI-6
ZERO Divice Error V-16
«ZEROP NOM)
(PROGl (CDR LST) (RPLACD LST NIL»
( POP LST) ) » . (SPACES NOM)
( (BCK-SPACE$ NOM) »
~FUN MENUS (LAMBOA (LST (DEFUN BCK-SPACE$ (LAMBDA (NOM)
READCB ) (LOOP
:SPACES 11) «NOT (PLUSP NUM»)
:PRINl ·OPTIONS: .) (PRINl BACK)
,MAPC LST <QUOTE (LAMBDA (LINE) (SETQ NOM (SUB1 NOM» ) »
(PRINl (CAR LINE» (SPACES 2)
(HAEC (CDR LINE) (QUOTE (LAMBOA (WORD) (DEFON aOME$ (LAMBDA ()
(PRINl WORD) (PRINT HOME)
(SPACES 1)
(TE...~RI)
») , »
(PRINl HOME)
(SPACES 20) ») (DEFUN SPACES (LAMBDA (CHARS)
TERPRI) (SPACES 6) (EO CHARS • • ) »
PRINl -ENTER CHOICE: .)
LOOP
I .
«ASSOC (READCB) LST) (DEFUN PRIN2 (LAMBDA (EXP PRIN1)
(PRINT RATOM) ) ) » (PRINl EXP) »
FUN QOERY$ (LAMBDA (TEXT)
c (DEFUN APPEND (LAMBDA (LST TAIL)
TERPRI) «NULL LST) TAIL)
SPACES (DIFFERENCE 18 (LENGTH TEXT») (CONS (CAR LST) (APPEND (CDR LST) TAIL» »
PRINl TEXT) (PRINl :) (SPACES 1)
RD-LIN$) » (DEFUN ADDl (LAMBDA (NOM)
(PLUS NOM 1) »
FUN RD-LIN$ (LAMBDA (
WORD LINE) (DEFUN SOBl (LAMBDA (NOM)
LOOP (DIFFERENCE NOM 1) »
(SETQ WORD (RD-WRD$»
( «NOLL WORD» (DEFON MAPe (LAMBDA (LST FeNC)
(POSH WORD LINE) ) (LOOP
( (EO RATOM. CR) ( (NOLL LST) NIL)
(REVERSE LINE» ) » (PONe (POP LST» ) »
E"UN RD-WRD$ (LAMBDA (
WORD )
,
r.,OOP
«(OR (FLAGP (READeR) (QUOTE DEL-<:BAR» (EQ RATOM ell»)
o
«NULL WORD) NIL)
(PACX (REVERSE WORD» )
(POSH RATOM WORD) ) »

:'ON UP-tINS (LA.\mDA (NOM).


:ZEROP NOM»
)RIN1 CR)
,ooP
(PRINI UPLINE)
{SETQ NOM (SOBl NOM»
( (NOT (PLUSP NOM}» ) »
'O~ BACKUPS (LA.~BDA (NOM)
lCK-SPACE$ NOM)

-~
2
(PUTQQ P ~XECUTIVE
(LAMBDA (
N.A11E INn ICATOR
)
(SETQ NAME (QUERYS (QUOTE NAME»)
( (NULL NAME»
******.******** E 0 ITO REX E COT I V E *****************\ ,-- (SETQ INDICATOR (QOERY$ (OOOTE INDICA~OR»)
L «NULL INDICATOR»
(DEFON DRIVER (LAMBDA () (EDIT-TXT (POT-TO-TXT (CAR NAME) (CAR INDICA'rOR») »
(SETQ RDS)
(SETQ WRS) (POTQQ E EXECUTIVE (LAMBDA ()
(SETQ ECHO) (LOOP
(SETQ *DRIVE*) (TERPRI)
(SETa PRINl (QUOTE PRIN1» (PRINl "* .)
(TERPRI 4) «EQ (PRINT (EVAL (READ») EXIT» ) })
,
(SETQ READeR) (POTQQ Q E-~ECOTIVE (LAMBDA ()
( «EO CTRL-Z (QUOTE CTRL-Z» (LOOP
(LOOP (TERPRI)
«EQ (READCB) CR» ) (PRINl - • • )
(PRINl -TYPE CTRL-Z: .) «EQ {PRINT (APPLY (READ) (READ») EXIT» ) »
(SETQ CTRL-Z (READCB»
(SET CTRL-Z (QUOTE CTRL-Z») (DEFUN EXIT (LAMBDA ()
(SETa READeR T) EXIT »
(SPACES 12)
(PRINl -*** The muSTAR AIDS **.-)
(LOOP
(LINELENGTR (ADOl LIN-LENS»
o (POTOQ T EXECUTIVE (LAMBDA ()
(TRACE (QOERY$ "FUNCTION NAHE(S)-» »
(TERPRI 3) (POTOO tJ EXECUTIVE ( LAMBDA ( )
(,SETQ CBAR$(MENUS MENUS» (ONTRACE (QUERY$ -FUNCTION NAME(S)·» »
(APPLY (GET CHAR$ (OCOTE EXECtT.rIVE») ) »
(POTOQ R EXECUTIVE (LAMBDA (
(SETQQ LIN-LENS 78) NA."1E ECHO )
(SETQO PAG-LEN$ 24) (LOOP
(SETa NAME (OOERYS "FILE NAME·»
(SETOQ MENUS ( «NULL NAME»
(F' EDIT FUNCTION) (SETO NAME (CAR NAME»
(V EDIT VARIABLE) «RDS NAME (QCOTE LIB) ·ORIVE·»
(P EDIT PROPERTY) (TERPRI)
(E EVAL LISP) (PRINT "FILE NOT FOUND-)
(0 EVAL-QOOTE LISP) ( (NULL NAl1E»
(T TRACE FUNCTION) (LOOP ,
(0 UNTRACE FUNCTION)
(R READ FILE)
(W WRITE FILE)
o (EVAL (READ»
( (NULL RDS}) ) »
(D SELECT DRIVE) » (POTQQ W EXECUTIVE (LAMBDA ()
(W-EXEC) »

POTQQ F EXECUTIVE (LAMBDA (DEFUN W-EXEC (~~DA (


LST ) NA.~E ECHO)
(SETQ LST (QOERY$ -FUNCTION NAME(S)-» (SETQ N&~E (QUERY$ -FILE NAME W »
({NOLL ~ST) ( (NULL NAME»
(EDIT-TXT (DEF-TO-TXT LST)) » (SETQ Nk~E (CAR N~~E»
(WRS NAME (OOOTE LIB) *DRIVE*)
POTQQ V EXECUTIVE (LAMBDA ( (PRIN2 (LIST (QUOTE PUTD) (~UOTE DEFON) (LIST
LST ) .(QUOTE QUOTE) (GETD DEFON) »)
(SETQ LST (QUERYS 8VARIABLE NAME(S)·»
«NULL LST» .
(EDIT-TXT (SET-TO-TXT LST» »
(TERPRI)
(PRIN2 (LIST (QOqrE DEFUN) (QOOTE SETQQ) (GETD SETQQ») k****** •• ****** TEXT EDITING FUNCTIONS ****** •• ************.,
(TERPRI)
(PRIN2 (LIST (COOTE,DEFUN) (QUOTE PUTQQ) (GETD PUTQQ») C ~FON EDIT-TXT (LAMBDA (-TEXT·
(TERPRI) ·PRE-TEXT* ·POST-TEXT* *ROW* ·COL* *INSERT* ·STRING* CHARS READeR
(PRIN2 (LIST (QUOTE DEFUN) (QOOTE FLAGQQ) (GETD FLAGQQ») (SETQ ·PRE-TEXT*)
(TERPRI 3) (SETQ ·POST-TEXT* (SPLIT$ *TEXT* PAG-LENS»
(PRT-TXT (PUT-TO-TXT NAME lOOOTE FUNCTIONS») (LOOP
(TERPRI) (SETQ *ROW* *TEXT·)
(PRT-TXT (POT-TO-TXT NAME (QUOTE VARIABLES») (SETQ *COL* (CADR *ROW*»
(TERPRI) (DISP-TXT *TEXT· *ROW* ·COL·)
(LOOP
(HAFC (GET NAME (QUOTE FUNCTIONS» (QUOTE (LAMBDA (ATM) (SETQ CHARS (READCB»
(TERPRI)
«EQ {CAR (CADDR (GETD ATM») (OOOTE ~RACE» «EQ (EVAL CHARS) (QUOTE CTRL-K») , EXIT EDIT CHAR
(ONTRACE (LIST ATM» ( «FLAGP CHARS (QUOTE DEL-CHAR»
(PRT-TXT (DEF-TO-TXT (LIST ATM») (DEL-CHAR C~ARS) )
(TRACE (LIST ATM» ) «OR {FLAG2 CHARS (QCOTE PRT-CHAR» (NUMBERP CHARS»
{PR~-TXT (DEF-TO-TX~ (LIST ATM») ») (PRT-CHAR CHARS) }
:TERPRI) (APPLY (£VAL CHARS) (LIST *INSERT*» ) )
(CTRL-F)
:HAFC (GET NAME (QOOTE VARIABLES» (QUOTE (LAMBDA (ATM)
(TE.R.PRI) (TE.~RI (LENGTH -ROW·»
( «EQ ATM (EVAL ATM») O· (SETQ CHARS (MENUS (QCOTE
(PRT-TXT (SET-TQ-TXT (LIST Ant») ) (E EVALOATE TEXT)
(MAPC (CDR ATM) (OOOTE (LAMBDA (EXP) (A ABANDON TEXT)
(TERPRI) (C CONTINUE EDIT) »»
«ATOM EXP) «EQ CHARS (QQOTE A»)
(PRIN2 {LIST (OOOTE PLAGQQ) A'rM
(TERPRI) )
En» ( (AND
(EQ CHARS (QUOTE E)
(PRT-TXT (POT-TO-TXT Ant (CAR EXP»)
TERPRI)
») ») (£VAL-TEXT (CONS NIL (APPEND.
(REVERSe ·PRE-TEXT·)
PRINT - (ROS) .) (APPEND (CDR *~EXT·) -POST-TEXT·) ») » ) »
WRS) » _
TQQ 0 EXECUTIVE (LAMBDA ( ~ON PRT-CBAR (LAMBDA (CHARS , PRINTABLE C1lARS ,
CHARS) TOKEN )
LOOP (PRINl (COND
. (SETa CHARS (QOERY$ -DRIVE LETTER-» «(GET CHARS (QUOTE ALIAS»)
( (~"ULL CHA.~S» (CHARS) »
(SETQ CHARS (CAR CHARS» (NOLL (CDR *COL·»
«EQ (L~~GTH
(h"ULL CHA.RS»
CHARS) 1» ) o ~
(INSERT-PRT CHARS) )
(NOT *INSERT·)
SETQ *ORIVE* CHARS) » (SETQ TOKE~ (OELETE-CSAR»
(INSERT-PRT CHARS) )
(INSERT-PRT CHARS)
(PRT-REST-LINE *ROW* *COL* 0) »
\PC (QUOTE (
\ BCD E F G H IOJ K L M N 0 P 0 R STU V W x y Z
1 bed e f 9 b i j k 1 m n 0 p q r s t u v w x y %
t t $ '- • * + - / : i < • > ? @ \ A 1 } - -,. •••• »
_ ,. {

(QUOTE (Lk~BDA (CHARS) (FLAG CHARS (QUOTE PRT-CHAR»» )

~FON DEL-CHAR (LAMBDA (CHARS , DELIMITER CR&~S ,


TOKEN )
(PRINl CHARS)

6 ('1\
(NOLL (CDR *COL*»
(INSERT-DEL CHARS)
(NOT * INSERT- ) (CTRL-J)
(SETQ TOKEN (DELETE-CBAR» (- ((CDR.·COL*» ) )
(INSERT-DEL CHARS) ,) (PRT-TOK TOKEN)
INSERT-DEL CHARS) (LOOP
PRX-REST-LINE ·ROW* ·COL. 0) » «NOT (SPACES (NEXT-RIGHT-TOKEN»»
(MOVE-RIGHT-TOKEN)
?C (QUOTE ( • • . , . -(- -)- -._ W[ __ ]. » . (SPACES 1) ) »
200TE (LAMBDA (CHARS) (FLAG CHAR$ (QCOTE DEL-CHAR»»
(DEFON CTRL-B (LAMBDA ( , MOVE TO END LINE
TOKEN)
~UN CTRL-P (LAMBDA ( (LOOP
CHARS )
, ESCAPE CHAR , (SETQ TOKEN (MOVE-RIGHT-TOKEN»
iETQ CHARS (READeR» ( (NULL TOKEN»
IRT-c.BAR CHARS) » (PRT-TOK TOKEN) ) »
QQ - (- ALIAS {)
QQ .). ALIAS }) (DEFON CTRL-S (LAMBDA ( , RETREAT CHAR \
2<2 • - AI. IAS -J CHARS TOKEN )
(SETQ TOKEN (CAR ·COL*»

IN CTRL-V (LAMBDA ()
, TOGGLE *INSER~* ,
o «ATOM TOKEN)
«MOVE-LEFT-TOKEN)
~TQ *INSERT* (NOT *INSERT.» » (BCK-SPACE$ 1) )
«NULL (CAR *ROW*»)
IN CTRL-D (LAMBDA ( , ADVANCE CHAR , (CTRL-E)
:HA.t"{$ TOKEN ) . (CTRL-B) )
:TQ TOKEN (NaT-RIGHT-TOKEN» (BCK-SPACES 1)
roLL TOKEN)
. (l1"ULL(CDDR .ROW*»)
CTR!.-K) )
, IF A~ !NO
,
OF co~ LINE
AND NOT END OF 'rEXT, ,,"
, (SETO TOKEN (UNPACK$ TOKEN»
«NULL (CDR TOKEN»
«OR (NOLL (CDR *COL*» (ATOM (CADR ·COL·»)
.TOM TOKEN)
PRIN1 TOKEN)
, '.mEN NEl-l LINE.
, IP TOKEN IS A DELIMITER ,, (SETQ *COL* (RDC$ (CADR *ROW*) *COL·» )

MOVE-RIGHT-TOKEN) )
TO TOKE.'i (UNPACKS TOKEN»
, PRINT TOKEN AND
, ADVANCE COL. , (RPLACA (CDR ·COL*) (PACKS (APPEND TOKEN (CADR *COL*»»
(SETQ *COL* (ROes (CADR *ROW·) *COL*»
(RPLACD *COL* (CODR *COL*» )
l"O CHARS (CONS (POP roXEN») (SETa CHARS (CONS (CHOPS TOKEN»)
r-TOK CHARS) (RPLACA *COL* TOKEN)
:-OM (CAR ·COL *) ) «(OR (NULL (CDR *COL·» (ATOM (CAOR *COL*»)
(NOLL TOKEN) (RPLACD *COL* (CONS CHAR$ (CDR ·COL*») )
(POP ·COL*) )
tPLACD "COL* (CONS CHARS (CDR *COL*»)
~OP *COL*)
o (RPLACA (CDR "'COL*)

(MOVD CTRL-S CTRL-B)


(NCONC CHARS (CADR *COL*»)

,
»
RETREAT CHAR \
~LACA (CDR ·COL·) TOKEN) )
ACA *COL* (APPEND (CAR ·COL*) CHAR$)"
LL TOKEN) (DErUN CTRL-A (LAMBDA , RETREAT TOKEN ,
PLACD ·COL· (CODR .COL.» TOKEN)
ACA (CDR ·COL *) TOKEN) » (LOOP
(SETQ TOKEN (MOVE-LEfT-TOKEN»
«NOT (SPACES TOKEN»).
CTRL-P {LAMBDA ( , ADVANCE TOKEN , (PRINl BACK) )
tEN ) {(NULL TOKEN)
J TOKEN (MOVE-RIGHT-TOKEN» (LOOP
~L TOKEN) «NULL (CAR *ROW*»)
)oP (CTRL-E)
'(NULL (CDDR *ROW*») ({CDR *COL*)
(CTRL-B) ) ) )
(BCK-SPACES (TOK-?RT-~EN TOKEN») »
8 .~
( (NULL *PRE-TEXT-»
~FUN CTRL-O (LAMBDA ( ) , MOVE TO BEGIN LINE \ -.... (SETQ NUM (SUBl NOM»
(PRINl CR) \,.) ( (ZEROP NOM»)
:SETQ ·COL* (CADR *ROW*» (SETQ *ROW* *TEXT*)
',SPACES (CAR ·COL*» ') (SETQ ·COL· (CADR ·ROW*»
(DISP-TXT *TEXT* *ROW* *COL*) j)
:FON CTRL-E (LAMBDA ( , MOVE UP LINE ,
NOM) (DEFUN CTRL-Z (LAMBDA () , SCROLL UP ,
(NULL (CAR *ROW·» «NULL *POST-TEXT*»
«NULL *PRE-TEXT*» ( «NOLL (CAR *ROW*»
(CTRL-W) (CTRL-X) ) )
(CTRL-E) ) ( «EQ *ROW* (CD~··TEXT*»
SETQ NOM (SPAC~S» (SETQ *ROW* *TEXT*) ) )
OP-LIN$ 1) (HOMES)
SPLICE-TOKEN *COL*) (TERPRI (SUBl PAG-LEN$)}
SETQ *COL* (CAR *ROW*) (PRT-ROW (CAR *POST-TEXT*»
SE~Q *ROW* (ROeS *TEXT* *ROW*» (TERPRI)
SPACES (CAR ·COL·» (PUSH (<:ADR *TEXT*) *PRE-TEXT'*)
(,.OOP (RPLACD ·TEX"!'* (CDDR *TEXT*»
«NOLL (CDR *COL*»)
«NOT (LESSP (SPACES) NOM») o (NCONC *TEXT· (CONS (PO~ *POST-TEX~*»)
(MOVE-CUR *TEXT* *ROW* *COL·) »
(CTRL-F) ) »
(DEFON CTRL-C (LAMBDA ( , SCROLL UP PAGE ,
~UN CTRL-X (LAMBDA (. , MOVE DOWN LINE , NOM)
NOM) ( (NOLL * POST-TEXT*) )
:NULL (CODR *ROW*» (SETQ NOM (D!FFERENCE PAG-LENS 6)
«NULL *POST-'rEXT*» (LOOP
(CTRL-Z) (PUSH (CADR *TEXT*) ·PRE-TEXT'*)
(CTRL-X), )
(RPLACD *T~'::XT* (CDDR *~EXT*»
;ETQ NOM. (SPACES»
:TRL-J)
{NCONC *T~'T* {CONS (POP *POS~-~EXT'*))

.OOP
«NULL *POST-TEXT'*})
(SETQ NUM (SOBl NOM»
«NULL (CDR *COL*») ( ZEROP NOM» )
«NOT (LESSP (SPACES) NOM») ( S ETQ • ROW'" *T EX'r* )
(CTRL-F) ) »
(SETQ *COL* (CADR *RO'W*»
(DISP-TXT *TEXT* *ROW* *COL*) »

ON CTRL-W (LAMBDA ()
NOLL *PRE-TEXT*»
({~uLL(CDDR *ROW*»
, SCROLL DOWN ,
o (DEFUN CTRL-N (LAMBDA ( , INSERT NEW LINE \
NUM)
(CTRL-E) ). )
«~1JMBERP (CAR *COL*»
PLACD *TE.XT* (CONS (POP ·PRE-TEXT*) (CDR *TEXT*»)
(SETQ *COL* (CONS a})
aSB (CHOPS *TEXT*) *POST-TEXT*) (RPLACD *ROW* (CONS ·COL* (CDR *ROW*»)
«NULL (CAR *ROW*» ( «GREATERP (LENGTH *TEXT*) PAG-LENS)
(POP ·ROW·) ) )
(PUSH (CHOPS *TEXT*) *~OST-TEXT*)
ISP-TXT *TEXT· *ROW* ·COL*) » (SETQ h~M (ROW-PRT-LEN (CAR *POST-TEXT·)})
(SETQ NUM 0) }
ON CTRL-R (LAMBDA ( · , SCROLL DOWN PAGE ,
NUM ) (ROLL-OWN-ROW (CDR *ROW*) NOM) )
~1JLL*?R.E-TEXT·) (RPLACD (CDR *ROW*) (CONS (CONS 0) (eDDR *ROW·»)
(CTRL-J)
8TQ NOM (DIFFERENCE PAC-LENS '6» ( «GREATERP (LENGTH ·TEXT·) PAG-LENS)
JOP
(PUSH (CHOPS *T~XT-) *POST-T~~T·) (PUSH (CHOPS *TEXT·) *POST-TEXT*)
(RPLACD *TEXT* {CONS (POP *PRE-TEXTW) {CDR *TEXT*»} {SETQ NUM {ROW-PRT-LEN (CAR *POST-TEXT*»))
(SETQ NUM 0) )

10 ria
(PRINl CR)
(SPACES (ROW-PRT-LEN (CADR -ROW*»)
(ROLL-OWN-ROW (CDR *ROW*) NOM) » (PRINl CR)
'\ ... (SETQ *COL* (CONS 0»
(DEFUN CTRL-J (LAMBDA' () , NE'W'LINE TAB , (RPLACA (CDR *ROW*) *COL·) )
«NOLL (CDOR *ROW*») «AND (NULL *POST-TEXT*) *PRE-TEXT*)
(SPLICE-TOKEN *COL*) (RPLACD *TEXT* (CONS (POP *PRE-TEX~*) (CDR ·TEX~*»)
(SETQ *ROW* (CDR *ROW*» (RPLACD *ROW* (COOR *ROW*»
( T'ER,pRI') (SETQ *COL* (CADR *ROW*»
(SETO *COL* (CADR *ROW·» (DISP-TXT *TEXT* *ROW* *COL*) )
(SPACES (CAR *COL*» » «NULL *POST-TEXT*»
(NCONC *TEXT* (CONS (POP *POST-TEXT*»)
(DErON CTRL-M {LAMBDA (*INSERT*) , CARRIAGE RETURN , (ROLL-UP-ROW (CD~ *ROW*»
( (EVAL *INSERT· ) (RPLACD *ROW* (CDDR *ROW*»
(CTRL-N) (SETa *COL* (CADR *ROW*»
(CTRL-F) ) (SPACES (CAR *COL*» »
(NOLL (eDOR -ROW·»
({NULL ·POST-TEXT·)
(SPLICE-TOKEN *COL*) (DEFON CTRL-O (LAMBDA ( , FIND TOKEN \
(SETQ *ROW· (CDR *ROW*» READCH )
(TERPRI) (BO~.E$ )
(SETa *COL* (CONS 0»
(RPLACD -ROW· (CONS -COL·»
«GREATERP (LENGTH *TEX':') PAG-LEN$)
o (SPACES (ROW-PRT-LEN (CADR *TEX'r*»)
(PRINl CR)
(PRINl -FIND NAME? .)
. (POSH (CADR *TEXT·) *PRE-TEX~*) . (SETO READCB T)
(RPLACD *'rEX'!· (CDDR *TEX'.r*») ) (SETQ *STRING* (CAR (RD-LIN$»)
(CTRL-Z) (HOMES)
(CTRL-K) ) (SPACES LIN-LENS)
(SPLICE-TOKEN -COL-) (HOMES)
(TE.~RI) (PRT-ROW (CADR *TEXT*»
(SETQ *ROW* (CDR *ROW*» «NULL *STRING*)
(SETQ ·COL* (CADR *RCW*» (MOVE-CUR *TEXT'* -ROW· *COL*)
(LOOP . (CTRL-L) »
«ZEROP (CAR ·COL·»)
(RPLACA *COL- (SOBl (CAR ·COL*») (DEFON CTRL-L (LAMBDA () , SEARCR AGAIN \
(RPLACD *CQL* (CONS (QUOTE • -) (CDR *COL*») ) » «NULL *STRING*»
(MOVE-RIGHT-TOKEN)
(SReB-TXT ·STRING* *ROW* *COL*)
"""'EFON CTRL-G (LA!'..BDA ( , DELETE CHAR , (MOVE-CUR *TEXT* *ROW* *COL*) »
TOKEN )
(SETQ TOKEN (DELETE-CRAR» () (DEFtrn SReH-TXT "(LAMBDA (TOKEN ROW COL)
( (NULL TOKEN» (LOO!?
(PRT-REST-LINE *ROW* *COL* 1) » «SETQ COL (SRCE-ROW COL»)
(SETQ *COL* COL)
DEFON CTRL-T (LAMBDA ( , DELETE TOKEN , (SETa *ROW* ROW) )
TOKEN NUM) (POP ROW)
(SETQ TOKEN (DELETE-TOKEN» ({NULL (CDR ROW»
( (NOT TOKEN» (SETQ ROW *TEXT*)
(SETQ NOM (TOK-PRT-LEN TOKEN» (LOOP
(LOOP (SETQ COL (CADR ROW»
«NOT (SPACES (NEXT-RIGHT-TOKEN)) «SETQ COL (SRCS-ROW COL»
{SETQ NUM (ADOl NOM» (SETQ *COL* COL)
(DELETE-CHAR) ) (SETQ *ROW* ROW) )
(PRT-REST-LINE *ROW* *COL* NOM) » (POP ROW) ) )
(SETQ COL (CADR ROW)} ) »
)EFUN CTRL-Y (LAMBDA () , DELETE LINE ,
«NULL (eDOR *ROW*»
13
12
b
~.'#i
***************** CURSOR CONTROL PRIMITIVES *******************'
';«EFUN SRCH-ROW (LAMBDA (COL)
(LOOP . l (DEFUN INSERT-PRT (LAMBDA (CHARS)
{(ATOM (CAR *COL*»
«NOLL (CDR COL» 'NIL)
«EO TOKEN (CAADR COL» COL) (RPLACD *COL· (CONS (CONS CHARS) (CDR ·COL*»)
(POP COL)
(POP ·COL*) )
(EO COL *COL*) COL) ) » (RPLACA ·COL* (NCONC (UNPACKS (CAR ·COL*» (CONS CHARS») »
(DErON INSERT-DEL (LAMBDA (CHAR$)
«(AND (NUMBERP (CAR ·COL·» (SPACE$ CHARS»
(RPLACA ·COL* (AnOl (CAR *COL*») )
(RPLACD *COL* (CONS CHARS (CDR ·COL*»)
(SPLICE-TOKEN ·COL*)
(POP ·COL*») .

{::)E:U~~ DELETE-CHAR (LAMBDA


CHARS TOKE.~ )
(SETQ TOKEN (NEXT-RIGHT-TOKEN»
( (~uLL TOKEN) NIL)
o «ATOM 'rOKEN)
(RPr;ACD ·COL* (enOR *COL·»
TOKEN)
(SETQ TOKEN (UNPACKS TOKEN»
(SETQ CHARS (CONS (POP TOKEN»)
( (NULL TOKEN)
(RPLACD *COL * (CDDR ·COL·»
CHARS )
(RPLACA (CDR *COL·) TOKEN)
CHARS » <

(DEFUN DELETE-TOKEN (LAMBDA (


TOKEN) .
(SETQ TOKEU (NEXT-RIGHT-TOKEN»
«NULL TOKEN) NIL)
(RPLACD ·COL* (CDDR ·COL*»
TOKEN) )

() (DEFUN MOVE-RIGUT-TOKEN (LAMBDA


TOKEN )
(SETQ TOKEN (NEXT-RIGHT-TOKEN»
«NULL TOKEN) NIL)
({Alm (NUMBER? (CAR *COL*}) (SPACES TOKE.~»
(RPLACA *COL* (ADOl (CAR *COL*»)
(RPLACD *COI.. * (CDDR *COL*»
TOKEN ) ,
«(SPLICE-TOKEN *COL*)
(POP ·COL*)
TOKEN)
TOKEN) )

(DEFUN NEXT-RIGHT-TOKEN (~~BOA ()


(NULL (CDR *COL*) NIL)
(CADR *COL*) »

14 (1) 15
•~ ;!~>~) \ * * * ,.. * * * * * * * * • .. '* * * T EXT P R I N T E R ********************\
r
t
(DEFUN ROLL-UP-ROW (LAMBDA (LINE
NUM LENGTH )
~ ~ (SETQ LENGTH (SUBl (LENGTH LINE»)
,EFUN MOVE-LEFT-TOKEN (LAMBDA , (SETQ NOM (REPL-ROW (CAR LINE) 0»
TOKEN ) ~ . (POP LINE)
(SETQ TOKEN (CAR *COL*» l (LOOP
«NUMBERP TOKEN) ( (NULL LINE»
«ZEROP TOKEN) (SETQ NUM (REPL-ROW (POP LINE) NOM»
NIL) (TEJtPRI) )
(RPL.ACA *COL* (SOBl -rOttEN» (SPACES NOM)
..
(RPLACD *COL* (CONS • • (CDR *COL·»)
)
(SPLICE-TOKEN *COL*)
(OP-LINS LENGTH) »
(DEFON ROLL-OWN-ROW (LAMBDA (ROW NOM)
(SETQ *COL* (ROes (CADR *ROW*) *COL*» (TERPRI (50B1 (LENGTH ROW)})
rOKEN » . (SETQ ROW (R-~ERSE ROW})
, {LOOP
~(.,." ' (SETQ NOM (R.::PL-RQW (POp· ROW) NOM») I
~FUN SPLICE-TOKEN (LAMBDA (COL
«NULL ROW»
LST' ) (UP-LIN$) }
. (ATOM (CAR COL» {PRINl CR} »
( (NO'! {NUMBERP (CAR COL»»
(POP LST)
(LOOP
o (DEFON REPL-RQW (LAMBDA (COL LENGTH
NUM)
( (OR (NULL LST) (NOT' (SPACES (POP LST»»)
(PRINl CR)
(RPLACA COL (ADOl (CAR COL») (PRT-ROW COL)
(RPLACD COr.. LST) ) )
(OR (h"ULL (CDR COL» {ATOM (CADR COL») (SETQ NOM (SPACES)
(RPLACA COL (PACK $ (CAR COL») (SPACES (DIFFERENCE LENGTH NOM»
NUM »
T )
RPLACA COL (PACK$ (APPEND (CAR COL) (CADR COL»»
(DEFUN DISP-TXT (LAMBDA (TEXT ROW COL) , DISPLAY TEXT ,
RPLACD COL (CDDR COL» (TE...tU'R! 47) , CLEAR SCREEN \
'IL » (BOME$) , MOVE TO aOMES ,
(PRT-TXT TEXT) , PRINT TEXT \
(MOVE-CUR TEXT ROW COL) » , RESTORE CURSOR ,
;\:. ':ztJN PRT-TXT (LAMBDA (TEXT) , PRINT TEXT \
• . (MAPC' (CDR TEXT) {QUOTE (LAMBDA (COL)
(PRT-ROW COL)
() (T E...~ RI ) ) ) »

t!(DEFON PRT-ROW (LA..~BDA (COL) , PRINT A ROW OF TEXT ~


t (SPACES (CAR COL)
{MAPC (CDR COL) PRT-TOK) »)

i(DEFON MOVE-CUR (LAMBDA (TEXT ROW COL)


(HOMES)
(LOOP , MOVE TO ROW ,
( (EO ROW TEXT»
(TERPRI)
(POP TEXT) )
(SETQ TEXT (CADR ROW)
'SPACES (CAR TEXT»
"\'~OOP \ MOVE TO COL \

17
'~
,~
**._ ••• *****.* S-EXPRESSION TO TEXT TRANSLATOR *••• **** •••• *•• \

( (EQ TEXT COL» .....; (DEFUN OE:F-TO-TXT {LAMBDA (VAR , TRANSLATE OEFINITIO
TXT)
(POP TEXT)
(PRT-TOK (CAR TEXT» ) » (- (SETQ TXT (CONS»'
(LOOP
(NCONC TXT (CDR
:DEFUN PRT-ReST-LINE (LAMBDA (ROW COL NO~
NOMQ ) ,. (EXP-TO-TXT (GETD (CAR VAR» (LIST (OOOTE DEFON) (POP VAR») »
(SETQ NOMO (SPACES» «NULL VAR) TXT)
(MA2C (CDR COL) PRT-TOK) (NCONC TXT (CONS (CONS 0») ) »
(SETQ NOM (DIFFERENCE (SPACES NOM) NOMO»
( (LESS? NOM NUMO)
(DEFUN SET-TO-TXT (LAMBDA (VAR , TRANSLATE VALOE ,
TXT )
(BCK-S?ACE$ NUM) ) {SETQ TXT (CONS»
(PRIN1 CR) (LOOP
(SETQ ROW (CADR ROW» (NCONC TXT (CDR '
(SPACES (CAR ROW» ,
(LOOP
(EXP-TO-TXT (£VAL (CAR VARl) (LIST (QUOTE SETQO) (POP VAR»)) ))
{ (NOLL Vi\...q) TXT)
«(EQ ROW COL» (NCONC TXT (CONS (CONS Ol}) ) »
{SE-rQ ROW (CDR ROW})
(PRT-TOK (CAR ROW» ) » 1 (DEFON POT-TO-TXT (LAMBDA (VAR ATM) , ~~SLATE PROPERTY %
(EXP-TO-TXT (GET VAR ATM) (LIST (QUOTE POTQQ) VAJ1 ATM)} »
~EFUN PRT-TOK (LAMBDA (TOKEN)
({ATOM TOKEN)
(PRINl TOKEN) )
o (DEFUN EXP-To-TXT (LAMBDA (EXP LST
*~~XT* *LINE* *LENGTB* ~AB INDENT )
«NULL (CDR TOKEN) (SETQ TAB 0)
«NULL WRS) (SETQ INDENT 1)
(PRINl (COND ( «LESSP LIN-LEN$ 60»
({GET (CAR TOKEN) (OOOTE ALIAS») (SETQ I~~ENT 2) ) .
«CAR. TOKEN» » ) (NF:ri-LIN TAB)
(PRIN2 (CAR TOKEN» ) (PUSH -(- *LINE*)
«NOLL WItS) (LOOP
(MAPC TOKEN PRIN1) ) «h1JLL LST»
(MAPC TOKEN PRIN2) » (EXP-TQ-LIN (POP LST»
tEFON ROW-PRT-LEN (LAMBDA (COL (POSS • - *LINE*) )
(TSK-To-TXT EXP TAB)
NOM) (POSH .). *LINE*)
,(SETQ NOM (POP COL» (N~.i-LIN TAB)
((LOOP '\ (R-~E..ttSE *TEXT1Ir) »
( (NULL COL) NOM)
(SETQ NOM (PLUS NOM (TOK-PRT-LEN (POP COL»» )) (DEFON TSK-TO-TXT (LAMBDA (TSK TAB) , TRANSLATE TASK \
() (SE1'Q TAB (PLUS TAB INDENT»
£FO~ TOK-PRT-LEN (LAMBDA (TOKEN) «(ATOM TSK)
«ATOM TOKE...~) 1) (EXP-TO-LIN TSK) )
«NOLL (CDR TOKEN» «ATOM (CAR TSK)}
(LENGTH (CAR TOKEN») «MEMBER (CAR TSK) (QOOTE (LAMBDA NLAMBDA»)
(L~GTR TOKEN) » (POSH "(" .*LINE*)
(EXP-TO-LIN (POP TSK»
(PUSH " " *LINE*)
(EXP-TQ-LIN (POP TSK»
(BOY-To-TXT TSK TAB)
(POSH It) *LINE*} )
It

«MEMBER. (CAR TSK) (OOOTE (LOOP COND PROGN PROGl AND OR))
(POSH -(" *LINE*)
(~XP-TO-LIN (POP TSK»

19
_&
18
(SETQ LENGTH {PLUS LENGTH (UNIT-LEN (CDR LINE»»
(BDY-TO-TXT TSK TAB) (LOOP
(POSH .). *LINE.) ) «NOT (L~SP LENGTH LIN-LENS»
(EXP-TO-LIN TSK) ) ( (SETQ ·LINE* (CONS TAB (CDDR LINE»)
«ATOM (CAAR TSK», (RPLACD LINE NIL)
(PUSH -(. *LINE*) (CUT-LIN *LINE* (CAR *LINE*» )
(TSK-TQ-TXT (POP TSK) TAB) (SETQ LINE (NXT-UNIT (CDR LINE»)
(Ah~ TSK (ATOM (CAR TSK» (NOLL (CDR TSK») «NULL LINE}) .
(POSH • • *LINE*) (SETQ LENGTH (PLOS LENGTH (ADDl (UNIT-LEN (CDDR LINE»») ) »
(EXP-To-~IN (CAR TSK»
(POSH .). *LINE*) ) (DEFUN UNIT-LEN (LAMBDA (LINE
(BDY-TO-TXT TSK TAB) PRINl ) . ,
(PUSH .). *LINE*) ) ( (OR (NULL LINE), (SPACES ,( CAR LINE) I» 0)
(POSH -(. *LINE*) (ATOM (CAR LIN~»
(POSH • • ·LINE*) I (ADDl (UNIT-LEN (CDR LINE))
(BDY-TO-TXTl TSK TAB) ( ({NULL WRS)
(PUSH .). -LINE·) » (SETQ PRINl T) ) )
(PLUS (LENGTH (CAAR LINE}) (UNIT-LEN (CDR LINE») »
1%jEFON BDY-TO-TXT (LAMBDA (BOY TAB) , T~~SLATE BODY ,
.~ ( (NULL BOY}) (DEFUN NX~-ONIT (LAMBDA (COL)
(NEfl-LIN TAB) (LOOP
»
(BDY-TQ-TXTl BOY TAB)

DEFON BDY-TO-TXTl (LAMBDA (BOY TAB)


o ({NULL (CDR COL» NIL)
«SPACE$ (CADR COL»
(SETQ COL (CDR COL»
COL)
) il
(LOOP
(TSK-TO-TXT (POP BOY) TAB)
«NULL BOY) ,
(PUSH • - *LINE*) }
(NEW-LIN TAB) ) »
)£FUN EXP-TO-LIN (LAMBDA (aP)
«ATOM EXP)
(PUSH (CONS EXP) *LINE*)
(PUSH -(- *LINE')
(LOOP
(EXP-TQ-LIN (POP EXP»
«ATOM EXP)
«NULL EXP»
(POSH • • *LINE*)
(PUSH -.- ·LINE*)
(POSS
(POSH
• • *LINE*)
(CONS EXP) *LINE*)
o
(PUSH • • *LINE·) )
(POSH -)- -LINE·) »

~UN NE".-1-LIN (LAMBDA (TAB)


:SETQ *LE~GTH* TAB)
:SETQ -LINE· (REVERSE -LINE·»
:SETQ TAB {PLUS (CAR *LINE*) (TIMES 2 IND~~»)
CUT-LIN *LINE- (CAR *LINE-»
SETQ *LINE· (LIST *LENGTB*) »
FON COT-Lr~ (~~BOA {LINE LENGTH}
;OSB *LINE* *T£AT*)
(NULL *LINE*» -

20
~ .*•• ***** T RAe E DEB 0 G GIN G PAC K AGE **********
(OEFUN TRACE {LAMBOA (LST)
-******.***** TEXT ~O S-EXPRESSION TRANSLA~OR .*.****.*********\ (SETQ INDENT 0)
(HAEC LST (QUOTE (LAMBDA (FON BODY FUNt)
DEFUN EVAL-TEXT (LAMBDA (TEXT
( (SETQ BODY (GETD FUN»
COL TXT ERROR ) (SETQ FUNt (PACK (LIST FUN t»)
(LOOP (MOVD FUN FUN~)
(SETO TXT (NXT-TOK» {{MEMBER (CAR BODY) (QUOTE (LAMBDA NLAMBDA»)
( (NULL TXT) '1') (PUTD FUN (LIST (CAR BODY) (CADR BODY)
(SETQ TXT (TOK-TO-SEX TXT» (LIST EVTRACE FON (CADR BODY) FUNt) )} )
( (NOT (NULL ERROR» NIL) (PRINl FUN)
(E"JAL TXT) ) » (PRINT • is not a LAMBDA defined function·) ») »

)EFUN TOK-To-SEX (LAMBDA (TOKEN) (DEFUN UNTRACE (LAMBDA (LST)


(MAPe LST (QUOTE (LAMBDA (FON FUNI).
(ATOM. TOKE~)
«EO TOK~ .(.) (SETQ FUN# {PACK (LIST FUN t)}
(LST-TO-SEX) ) ( (GETD FUNt)
(PRIN1- • SYNTAX ERROR-) (MOVD FON# FON)
(SETQ ER.~OR '!) ) (MOVD NIL FONt) ) ») »
((troLL (CDR TOKEN»
(DEFON EVTRACE (NLAMBOA (FUN ARGS FON~)
(CA.~ TOKEN) )
(PRTA.~GS FUN ARGS)
(PAC.~ TOKEN) »
£FUN LST-TO-SEX (LAMBDA
c (PRTRSLT FUN' (APPLY FONt (MAKARGS ARGS») »
(DEFON PRTARGS (LAMBDA (FUN ARGS)
TOKEN LST')
(SE'rO TOKEN (NXT-TOK» (SPACES INDENT)
(LOOP . (SETQ INDENT (PLUS INDENT 1»
«EO TOKEN .)W) (PRINl FON) (PRIN1· [-)
(REVERSE LST) ) «h\JLL ARGS)
(POSH (TOK-To-SEX TOKEN) LST) (PRINT • 1.) )
(LOOP
( (£VAL ERROR» «ATOM ARGS)
(SETQ TOKEN (NXT-TOK»
«EQ TOKEN ••• ) , (SETQ ARGS
(LOOP
(EVAL ARGS»
(SETO TOKEN (TOlt-ro-SEX. (NXT-TOlt))
«EO (NXT-TOK) .) ") (PRINl (POP ARGS»
( NCONe (REVERSE LST) -;rOltEN) ) «(ATOM ARCS»
(PRINl ·SYNTAX ERROR·) (PRINl ., .) ) )
(SETQ ERROR T) ) ) » (PRINl (EVAL (POP ARGS»)
( (~1JLL A.~GS»
'.FON NX'I'-TOK ( LAMBDA
(PRINl ., .) )
TOKE...~ )
LOO?
1 •

o (PRINT -1-) })

«(NOLL COL) (DEFON PRTRSLT (~~DA (FUN RSLT)


(SETQ TEXT (CDR TEXT» (SETQ It-t1)ENT (DIFFERENCE INDENT 1»
( (l'i~ TEXT) NIL) (SPACES INDENT)
(SETQ COL (CAR TEXT» (PRINl FUN) (PRIN1···) (PRINT RSLT)
(NXT-TOK) ) .r. RSLT »
(SETQ TOKEN (POP COL»
«NOT (OR (NOMBE.R2 TOKEN)
(S4?ACE$ TOKEN) (EQ -r~gEN .,.»)) (DEFUN ~~GS (LAMBDA (ARGS)
TOKEN ) ) }) «NULL ~qGS) NIL)
({ATOM ARGS)
(EVAL A..~GS) }
(CONS (EVAL (POP ARGS» (MAKARGS ARGS» »

""~
«(ATOM (CAR LST1»
(SOPERREVERSE {CDR LST1) (CONS (CAR LST1) LST2»)
'File: UTILITY. LIB (SUPERREVERSE (CDR LST1) (CONS (SOPERREVERSE (CAR LST1» LST2» »
08/11/80 The Soft Warehouse ,
(PROGI ••
(POm DEFUN (QUOTE (NLAMBOA (FONe DEF) , Function REMBER is a constructor returning a list in which all
(PUTD FUNe DEF)
occurrences of ATM has been removed from LST. ,
rUNe ») ) (DEFON ~~BER {~~BOA (ATM LST)
( (NULL LST) NIL)
, Function APPEND returns a list consistinq of the elements of LSTl «EQ ATM (CAR LST» ,
appended to LST2. , (REMBER ATM (CDR I,ST» )
(CONS (CAR LST) (REMBER ATM (CDR LST») »
(DEFON APPEND (LAMBDA (LSTl LST2)
«NOLL LST1) LST2) Function SUBST is a constructor returning the expression resulting
(CONS (CAR LST1) (APPEND (CDR LST1) LST2») » ,rom replacing all occurrences of OLD by NEW in EXPN. ,

, Function COpy returns a copy of its argument. , EFUN SUBST ( LAMBDA ( OLD NF:il EXPN)
( (EQOAL OLD EXPN) NE'W) ,
(DEFON COpy (LAMBDA (EXPN) «ATOM EXPN) EXPN)
«ATOM EXPN) EXPN) (CONS .(SUBST OLD NEW (CAR EXPN» (SUBST OLD N£W (CDR EXPN») »
\,
(CONS (COpy (CAR EXPN» (COpy (CDR EXPN») »
, tunction NTH is a selector wbich returns the result of
, Function ONION returns the union of LSTl and LST2. , removing 'the first NOM elements from the list LST. ,

(DEFON UNION (LAMBDA (LSTl LST2) (DEFON NTH (LAMBDA (LST NOM)
«NOLL LST1) LST2) «NOT (PLOSP NOM»
«ME.-.u3ER (CAR LST1) Lsr2) LST )
(ONION (CDR LST1) LST2» (LOOP
(CONS (CAR LST1) (UNION (CDR LST1) LST2» ») (SETO LST (CDR LST»
(SETO NOM (SUBl NOM»
( (ZEROP NOM)
, Function INTERSECTION returns the intersect~oft of LSTl and LST2. , LST ) ) »
\

(DEFON INTERSE~ION (LAMBDA (LSTl LST2)


«NULL LST1) NIL) t Punction GE~SYM is a constructor which returns a new name
«MEMBE..tt (CAR LST1) LST2) O~ the fo~ Gxxxx where xxxx is a number incremented each
(CONS (CAR LST1) (INTERSECTION (CDR LST1) LST2») time G~~SYM is called. , .
(INTERSECTION (CDR LST1) LST2) »
(SETQ GENSYM 0)

\ Function SUBSET is a comparator returning ~ iff LSTl .is a subset (DEFON GENSYM (LAMBDA (NOM LST)
of LST2. , (SETO NOM (DIFFERENCE 4 (LENGTH GENSYM»)
(LOOP
(OEFON SUBSET (LAMBDA (LSTl LST2) { (ZEROP NOM»
«NULL LST1» (POSH 0 LST)
«MEMBER (CAR LST1) LST2} . (SETO NOM (SOBl NOM» )
(SUBSET (CDR LST1) LST2» » (PROGl
{PACK (~CONC (CONS (QUOTE G) LST) (LIST GENSYM»)
(SETQ GENSYM (ADOl GE~SYM») ) »
\ Function SoPtRREVERSE returns A list of the elements of LSTl
reversed at all levels. \
\ Junction MAX returns the greater of two numbers. \
(DEFON SUPE~~~£RSE (LAMBDA (LSTl LST2)
«NULL LST1) LST2)
Function Gee returns the Grea~est Common Divisor of NOMl and
NUM2. \

(DEFUN MAX (LAMBDA (M N) ~OEFUN GCD (LAMBDA (NOMl NUM2


NUM3 )
«GREATERP M N) K) (LOOP .
N )J «ZEROP NUM2) NOM1)
(SETQ NOM3 NOM2)
(SETQ NUM2 (REMAINDER NOMl NUM2»
(OEFON ADDl (LAMBDA (NOM)
(.SETQ NUMl NUM3)) »
(PLUS NUM 1) »
(DEFUN SOBl {LAMBDA (NOM)
(DIFFERENCE NOM 1) »
\ The following are examples of Mapping Functions equivalent to
the definitions found in LISP tutorials. ,

, Function DEPTH returns the maximum depth of an expression. \ (DEFON MAPC (LAMBDA (LST FUN)
(LCOP
(DEFON DEI''!:! (LAMBDA (EXPN) \ \ ~iCLL LST) NIL)
(FUN (POP LST) ) )
({ATOM EXPN) 0)
(ADOl (l'~ (DEPTH (CAR EXPN» (DEPTH (CDR EXPN»») )
'EFON M.APCAR (LAMBDA (LST FUN)
«NULL LST) NIL)
, Function ABS returns the absolute value of NOM. , (CONS (FUN (CAR LST» (MAPCAR (CDR.LST) FUN» »

.- (DErON ASS (LA.~DA (NOM)


(DEFUN MAPLIST (~~DA (LST FUN)
( (~'1JLL LST) NIL)
«MINOSP NOM)
(KINOS NOM) ) (CONS (FUN LST) (MAPLIST· (CDR LST) FON» »
NOM »
(ROS) , DELETE THIS LINE IF YOU WANT AN EVALQOOTE DRIVER ,
'.Function FACTORIAL returns NOH factorial. ,
. ' .

(DEFUN FACTORIAL (LAMBDA (NOM \ Function DRIVER is 'originally defined in machine language to be
• ANS ) an EVAL-LISP executive driver. However, it may be redefined as
.'t ((NOT (GREATERP NOM -1» NIL) desired. The following is an ·EVAL-QOOTE driver I which must be
to load the remainder of the functions in this file. ,
(SETQ ANS·l)
(LOOP
«EQ NOM 0) ANS) {OEFON DRIVER (LAMBDA (RDS WRS)
(SETO ANS (TIMES NOM ANS») (LOOP (
(SETQ NOM (SUBl NOM» ) » (TERPRI)
(QOOTE • > .)
(~~ I;,,!~~l
(PRINT (APPLY ~ (READ) (READ) (TERPRI») ) »
, Function POWER returns NOM! raised to the NUM2 power. NOM3
isa local or temporary variable for the function PCWER. , (DRIVER)

(DEFON POWER (LAMBDA (NOMl NOM2


NOM3 )
(SETO NOM3 1)
(LOOP
(SETQ NCM2 (DIVIDE NOM2 2»
- ( «(EO (CDR NUM2) 1)
(SETQ NOM3 (TIMES NOMl NOM))
(SETQ NUM2 (CAR NUM2»
«ZEROP NUM2) NOM)
(SETa NUMl (TIMES NOM1.NOM1» ) »)

Das könnte Ihnen auch gefallen