Sie sind auf Seite 1von 42

STANFORD ART l Fl C I AL l NTELLIGENCE PROJECT

MEMO AI - 84
MLI SP USERS' MANUAL
BY
DAV I D CANF IELD S M ITH
JANUARY 1969
C OMP U T E R S C I E N C E D E P A R T ME N T
School of Humani ti es and Sciences
STANFORD UNI VERSI TY
STANFORD ARTIFICIAL INTELLIGENCE PROJECT
MEMO AI-84
MLISP USERS' MANUAL
by
David Canf i el d Smith
Computer Sci ence Department
School of Humanities and Sci ences
St anf or d Uni ver s i t y
.Sn nua ry, 1969
ABSTRACT: MLISP i s a LISP pr e- pr ocessor desi gned tc f a c i l i t a t e t he
wr i t i ng, use, and underst andi ng of LISP progrsms. Thi s i s
accomplished t hrough par ent heses r e d u c t i ~ n , comments, i nt r o-
duct i on of a more v i s u a l f l ow of c ont r ol w i t h block s t r uc t ur e
and mnemonic key words, and language redundancy. I n addi t i on,
some "met a-const ruct s" a r e i nt r oduced t o increase t he power
of the language.
Thi s r es ear ch was support ed by Grant PHS MH 066-45-07 and ( i n pa r t ) by the
Advanced Research Pr oj e c t s Agency, Department of' Defense ( SD-183) .
INDEX
Page
I. Introduction
A. Loading Sequence
B. Translator
C. Miscellaneous
11. Syntax
111. Semantics
A. <progra@
B. <expressio+
C* <block> - PROG
D. 'conditional expression> - CCfJE
E. <FOR expressio*
F. <FOR expression>
G. <UNTIL expressi.00
H. W I L E expression>
I. <list expressiorP
J. <arglist>, <argument>
K. <strin@
L. <function call>
Me <function definition>
N- <assignment expressio0
0. <infix operator>
P. <prefi+
Q. <identifier>
F:. <number>
IV. ,>pecial Constructs - Data Structures
V. MLICP Program
VI. bibliography
I. INTRODUCTION
MLISP i s a LISP ( ~ e f . 2) pre-processor wr i t t en a t Stanford Uni versi t y
by Horace Enea f or t he IBM 360167. re-processor" means t he MLISP programs
a r e t r ans l at ed di r e c t l y i nt o LISP s-expressions t o form a va l i d LISP pro-
gram, which i s t hen passed t o t he LISP i nt er pr et er o r compiler. The aut hor
has implemented MLISP on t he P D P - ~ / ~ O and has added a few auxi l i ar y f eat ur es,
among them compiled obj ect programs, f l oat i ng poi nt numbers, 3 new
FOR loop, improved e r r or messages and recovery, and addi t i onal s t r i ng mani-
pul at i on f a c i l i t i e s ,
As i t s name implies, MLISP i s a " m e t a - ~ ~ ~ ~ " language; MLISP programs
may be viewed as a superst ruct ure over t he underlying LISP processor. A l l
of t he underlying LISP funct i ons ar e avai l abl e t o MLISP, The purpose of
having such a superst ruct ure i s t o improve t he r eadabi l i t y and wr i t e a bi l i t y
of LISP, l ong (in)famous f or i t s obscuri t y. As LISP i s one of t he most
powerful symbol manipulative and l i s t processi ng languages, it seems appro-
pr i a t e t o attempt t o f a c i l i t a t e t he use of it.
Anyone who has attempted t o understand a l ar ge LISP program wr i t t en by
anot her programer ( or even by himself a month e a r l i e r ) qui ckl y becomes
aware of sever al f eat ur es:
( a)
The flow of cont r ol i s very d i f f i c u l t t o follow. Since comments
a r e not permitted, t he programmer i s completely unable t o i ncl ude wr i t t en
assi st ence.
(b)
An i nordi nat e amount of time must be spent bal anci ng parent heses.
It i s frequent l y a non- t r i vi al t ask j us t t o determine which expressi ons
belong wi t h what ot her expressions.
( c)
The not at i on of LISP i s f a r from t he most nat ur al o r mnemonic
f or a language, making t he understanding of most r out i nes overl y di f f i c ul t , ,
MLISP was designed wi t h t hese d i f f i c u l t i e s i n mind. The synt ax
reduces t he number of parent heses, permi t s comments, and c l a r i f i e s t he
fl ow of cont r ol . A more mnemonic and na t ur a l not at i on i s i nt roduced. Some
ffmet a-const ruct s" ar e added t o si mpl i f y t he format i on of complex expr essi ons.
St r i ngs and s t r i n g mani pul at i on f eat ur es , p a r t i c u l a r l y us ef ul f o r i nput /
out put , ar e i ncl uded. I n addi t i on, a s ubs t a nt i a l amount of redundancy
has been b u i l t i nt o t he language. Thi s us ual l y f a c i l i t a t e s t he wr i t i ng
of r out i nes, per mi t t i ng t he us er t o choose t he most na t ur a l from a v a r i e t y
of formul at i ons .
MLISP i s now running on t he St anford PDP-10. It cur r ent l y t r a n s l a t e s
a t a speed of around 1000 l i n e s pe r minute i n a t i me-shared environment.
The MLISP t r a n s l a t o r i s i t s e l f a compiled LISP program. Some e f f o r t has
been t aken t o keep t he t r a n s l a t o r a s machine independent a s pos s i bl e; i n
t heor y MLISP could be implemented on any machine wi t h a working LISP system
wi t h onl y minor changes.
The r e s t of t he i nt r oduct i on w i l l be devoted t o suppl yi ng t he i nf or -
mation necessary t o get an MLISP program running on t he St anford PDP-10.
Par t I1 of t h i s manual wi l l pr esent t he synt ax of MLISP; Par t 111, t he
semant i cs of t he language; Par t I V, some s peci al cons t r uct s and dat a
s t r uc t ur e s ; and Par t V, a complete MLISP program.
A. Loading Sequence
There a r e two ver si ons of MLISP, bot h r es i di ng on t he system ar ea of
t h e di s k:
MLISP - a core image cont ai ni ng LISP and t he compiled MZISP t r a n s l a t o r .
MLISPC - a core image cont ai ni ng t he LISP compiler i n addi t i on t o t he
above.
These programs may be loaded by ty-ping:
R MLISP <core si ze>
o r R MLISPC <core si ze> . Minimum r equi r ed core f o r MLISP i s , 7
and f o r MLISPC .
B. Tr ans l at or Commands
Af t er h i s MLISP program has been t r ans l at ed, a us er may s peci f y t h a t
t he LISP s-expressi ons a r e t o be (1) executed, (2) compiled, o r (3) out put
t o a s el ect ed devi ce i n a format s ui t abl e f o r l a t e r compi l at i on o r execut i on.
The supervi sory f unct i on named (you guessed i t ) MLISP provi des t he means
f o r accomplishing t hese a l t e r na t i ve s . Once t he us er has loaded t h e system
by ty-ping one of t he two commands above, he may begi n t r a ns l a t i on of h i s
MLISP program by t ypi ng one of t he fol l owi ng a l t e r na t i ve s :
(1) ( ~ I S P )
( 2) (MLISP <i nput filename>)
( 3)
(MLISP <i nput filename <out put filename> T)
(4)
(MLISP <i nput filename> <output filename> NIL)
These wi l l now be expl ai ned i n d e t a i l .
(1) (MLIsP) - No arguments. The t r a n s l a t o r assumes an i nput f i l e has
al r eady been s e t up wi t h t he LISP "INPUT" f unct i on. The t r a n s l a t o r does an
1 T ) t r a ns l a t e s , and t hen execut es t he t r a ns l a t e d program ( a "compile-
and-go" procedure) . ( s ee Quam's STANFORD LISP manual, r e f . 3, f o r expl anat i on
of t he i nput / out put funct i ons, DEFPROP, e t c .)
(2)
(MLISP <i nput filename>) - Same a s above except t h a t an IN^ DSIC:
<filename>) i s aut omat i cal l y executed bef or e t he (INC T) . The s pe c i a l case
(MLISP TTY) suppresses t he (INC T) and w i l l accept a program from t he t el et ype.
(3)
(MLISP <i nput filename> <out put filename> T) - Both an ( INPUT DSK:
<i nput filename>) and an ( OUTPUT DSK: <output filename>) a r e aut omat i cal l y
executed, and a l l out put except e r r o r messages and f unct i on names goes t o
t he di sk. The t h i r d argument, T, s pe c i f i e s t h a t t he t r a ns l a t e d f unct i ons
a r e t o be compiled; t he LAP code goes t o t he s el ect ed out put f i l e . Note:
wi t h t h i s a l t e r na t i ve a l l SPECIAL var i abl es must be decl ared bef or e t hey
a r e used i n a f unct i on. See Ref. 3 f o r more i nformat i on on SFECIAL var i abl es .
The MLISPC ver si on must be used f or t h i s a l t e r na t i ve .
(4) (MLISP <i nput filename> <out put filename> NIL) - (INPUT DSK:
<i nput filename>) and (OUTPUT DSK : <out put filename>) a r e execut ed t o s e t
up i nput and out put f i l e s on t he di s k. With t h i s al t er nat i ve, however,
i nst ead of t he f unct i ons bei ng compiled as t hey ar e defi ned, t hey ar e
GRINDEF1ed ont o t he out put f i l e . GRINDEF i s a LISP f unct i on which p r i n t s
f unct i on names and def i ni t i ons ont o t he out put f i l e i n a s pe c i a l form:
(DEFPROP <funct i on name> <fun& ion def i ni t i on> <i ndi cat or>)
which i s s ui t a bl e e i t h e r f o r l a t e r compi l at i on by t he LISP compi l er o r f o r
i nput i n t o t he LISP i nt e r pr e t e r . Thi s i s f r equent l y us ef ul if t h e us er
des i r es a "clean" system; he can read h i s DEFPROP' ~~ f unct i on de f i ni t i ons
i nt o a f r e s h LISP system ( i . e. , wi t hout t he MLISP t r a n s l a t o r e t . a l . ) t hus
making maximum uye of cor e st or age. The MLISP ( a s opposed t o MLISPC) cor e
image may be used wi t h t h i s al t er nat i ve.
C. Miscellaneous
It i s sometimes des i r abl e f o r t he user t o c a l l t he MLISP t r a n s l a t o r
under program cont r ol . Thi s i s made pos s i bl e by t he s peci al f unct i on
MTRANS; c a l l i n g M!I' RANS has t he fol l owi ng e f f e c t :
( a )
An MLISP program i s read from whatever i nput devi ce has been
s peci f i ed a t t he moment. The f i r s t char act er i n t he buf f er should be t he
f i r s t char act er i n t he program. See Par t I1 f o r t he de f i ni t i on of a
s ynt act i c MLISP program.
( b)
The r e s ul t i ng LISP program w i l l be r et ur ned a s t he val ue of
t h e funct i on.
Note t h a t t he f unct i on MZISP should - not be cal l ed under program cont r ol ,
s i nce it has s ever al s i de e f f e c t s which ar e gener al l y undesi r abl e i n a
program. MTRANS has no s i de ef f ect s . It r equi r es no arguments.
COMMENTS: Any sequence of char act er s encl osed by percent s i gns ($)
i s t aken t o be a comment and i s ignored by t he t r a ns l a t or . The val ue of
comments should be obvious: i n gener al t h e c l a r i t y of a program i s d i r e c t l y
pr opor t i onal t o t he number of comments.
There a r e s ever al MLISP-defined atoms t o which t h e us er may r e f e r :
ATOM
-
F
BLANK
RPAR
LPAR
DOLLAR
COMMA
SLASH
EQSIGN
STAR
VALUE
1
NIL
ATOM
-
COLON
PLUSS
DASH
DBQUOTE
PERIOD
PERCErn
CR
LF
FF
LARROW
ALTMODE
These f a c i l i t a t e t h e handl i ng of s p e c i a l c ha r a c t e r s .
11. smAx
The complete MLISP syntax follows. The LISP equivalents (into which
the syntatic parts are translated) are listed in Part 111. The meta-
symbols [ ] bracket optional elements which may be repeated zero or more
times. The curly brackets { ] enclose alternative elements.
<prograrO : := <expression> .
<express ion> : : = <simple expression> [ <infix operator> <simple express ion>]
<simple expression> : : = <block>
( <conditional expression>
I <FOR expression>
1 <UNTIL expression>
1 M I L E expression>
I <list expression>
I <strin@
1 <pref i 0 <simple expression>
I (<express ion>)
I <function call,
I <function def inition>
I <assignment expression>
1 '<s-expression>
1 <number>
I <empty>
<block> : := BEGIN [ <declaratio+; ] [ <expression>; ] END
<declaration> ::= NEW <identifier list>
SPECIAL <identifier list>
<i dent i f i er l i s t > ::= <i dent i f i er > [, <i dent i f i er > ]
I <empty>
<condi t i onal e xpr e s s i o0 ::= I F <expression> THEN <expression> [ELSE
<expre s s ion> 1
IN DO
<FOR express iorD : : = FOR <i dent i f i er > fON} <express ion>
C OLLECT
I
<expressiorD [UNTIL <expression> ]
1 FOR <i dent i f i er > { c] <expression> TO <expressiorD
[BY <expression> ]
DO
(COLLECT
) <expressiol?, [UNTIL <expression> ]
DO
W I L express i o 0 : : = lCOLLECT <express ion> UNTIL <express ion>
DO
GHILE expres sio* : := WHILE <expres sio* lCOLLECT 1 <expr essi oO
< l i s t expressi or0 ::=; < <ar gl i st > >
<st r i n@ ::= "<any sequence of charact ers - possi bl y none - except ">"
<funct i on cal l > : := <i dent i f i er > (<argl i st >)
<funct i on def i ni t i on> : := <i dent i f i er > ( I:) <i dent i f i er l i s t > :
<express ion>
<assignment expression> : := <i dent i f i er > [ <expr essi oO
<i nf i x operat or> : := *J"I - J / ( +I &l @l =
I <i dent i f i er >
<prefi x> := +I - ~NOTI N~TLLI ATOM
<i dent i f i er > ::= <l et t er > [ <any sequence of l e t t e r s or di gi t s > ]
<l et . t er> ::= A I B I C I . . . I x I Y I z I !
<dieit:, ::= 1(2(31415161718191@
111. SEWI CS
This sect i on w i l l serve two purposes:
.
(a)
Present t he LISP expressions i nt o which t he MLISP const ruct s
ar e t r ansl at ed;
(b)
Explain the "meta-constructs" and how t hey ar e evaluated.
I n t he following it w i l l be assumed t ha t t he user has a working
knowledge of LISP. McCarthy ( ~ e f . 2) provides a reference manual f or the
standard LISP functions, while Weissman ( ~ e f . 4) furni shes a good t ut or i a l .
I n t he cases below where t he meaning of MLISP const ruct s i s given by t h e i r
LISP equivalents, no f ur t her explanation w i l l be presented. Any non-
standard LISP elements w i l l be f ul l y explained; ~uarn' s users' manual
f o r Stanford LISP ( ~ e f . 3) may be consulted f or addi t i onal information.
A. CprograrO : : = Cexpres s ion>
Tn general MLISP programs ar e enclosed wi t hi n a BEGIN-END pa i r ; t ha t
is, a <progra@ i s usual l y a <bl ocD ( cf . C below). This permits more
than one MLISP expression t o be t r ansl at ed a t one time. ( see Par t V f or
a sample program.)
An expression i s a simple expression (paragraphs C-N) opt i onal l y
followed by any number of i nf i x operator-simple expression pai r s. There
i s - no hierarchy of operat ors; associ at i on i s t o t he r i ght . For example,
A + B - C will be t r ansl at ed as (PLUS A (PIFFEFJ~NCE B c ) ) . Again,
A CONS B CONS NIL w i l l become (CONS A (CONS B NIL) ) .
Examples of expressi ons a r e ( not e t h a t "3" means "is t r a ns l a t e d t o" ) :
A
16
A := x * 2 * (SETQ A (EXPP x 2))
A := B := c 3 (SETQ A (SETQ B c) )
l r ~ ~ ~ ~ IS A STRING"
( A + B) - c (DIFFERENCE (PLUS A B) C)
( ( ( A + B)) - c ) $ (DIFFERENCE (PLUS A B) C)
PLUS (A, B) - C 3 ( DI FFERENCE ( PLUS A B)
C)
DI FFEFENCE ( A + B, C) 3 (DIFFERENCE (PLUS A B) C)
FOR I IN L COLLECT CAR(I)
WI LE NOT ( A EQ B) DO A := READ( )
BEGIN A := B END CONS C ) (CONS (FROG NIL (SETQ A B) ) C)
Note t h a t si nce an oper at or may be an a r b i t r a r y i de nt i f i e r , v i r t u a l l y any
user-defi ned f unct i on of two arguments may be used a s an i n f i x operat or.
Parent heses may always be used t o a l t e r t he as s oci at i on of arguments; f o r
example :
( A CORS B) CONS C @ (CONS (CONS A B) c) .
The fol l owi ng paragraphs (c-N) expla i n simple expressi ons.
C. Ql ocW : := BEGI N [ <decl ar at i oO; ] [ <expression>; ] END
<decl arat i on> ::= SPECI AL <i de nt i f i e r l i s t >
( NEW <i de nt i f i e r l i s t >
BEGIN-END bl ocks a r e t r ans l at ed i nt o PROGTs. Vari abl es decl ared
usi ng NEW become t he PROG var i abl es ; a l l PROG var i abl es a r e i n i t i a l i z e d
t o NI L . The scope o f var i abl es so defi ned i s t he scope of t he PROG,
i . e. , u n t i l t he matching END. I f there a r e no rJEW decl ar at i ons, N I L i s
used for t he PROG var i abl es. Expressions within t he block a r e separ at ed
by semicolons. As wi t h PRQG's, a val ue may be ret urned f o r t h e bl ock
via t he RETURN funct i on. Again, l a s s may be t r ans f er r ed t o vi a t he
GO function; e.g., GO(L) . Labels may be formed by following t he l a be l
i de nt i f i e r i md i a t e l y wi t h a semicolon; e . go, L; . o ow ever t he i t er at i on
expressions described below (E-H) ar e t o be much recommended over l abel s
and GO t ransfers. ) An example of a block and i t s PROG t r ans l at i on follows.
E G I N
NEW A,B,C; NEW X;
A := READ ( );
X := (B + C) / A;
RETURN (x) ;
Er n
( PROG
(SETQ X (QUOTIENT (PLUS B C) A) )
SP,lXIAL decl arat i ons may be mixed i n with NEW decl ar at i ons i n any
manner* A l l NEW and SFECN decl arat i ons, however, must appear a t t he
s t a r t of a block, before any executable expression.
Variables declared SPECIAL have t he following ef f ect : (1) The
i ndi cat or "SPECIAL" i s immediately put on t he i r property l i s t s .
(2)
If t he t r ansl at ed MLISP program i s t o be GRINOEF'ed ( i . e. , pri nt ed) onto
an output f i l e (cf . Part I), a l l SFECIAL var i abl es ar e col l ect ed i nt o
a l i s t and ~Rr nEF' ed onto t he head of t he f i l e , before any funct i on
def i ni t i ons. Thus a l l SPECIAL vari abl es ar e guaranteed t o be defined
before they ar e used, no matter where t hey appear i n t he MLISP program,
This enables t he user t o mark var i abl es SPECIAL wherever i n t he program
it i s convenient t o do so. Note t ha t SPECLIU; var i abl es ar e not made
-
PROG var i abl es; t ha t i s done only wi t h NEW decl arat i ons. However, NEW
var i abl es may al so be declared SPECLBL.
. See Ref. 3 f or f ur t her di scussi on of SPECIAL
var i abl es.
D. <conditional expressiorD ::= I F <expression>
THEN i e x p r e s s i o 0 [ELSE <expression>]
Without t he opt i onal ELSE term,
i s t r ansl at ed i nt o
(COND (el e2) )
where el , e2 ar e any a r bi t r a r y expressions.
I f t he ELSE term i s present,
I F e l THEN e2 ELSB e3
becomes
(COND ( e l e2) ( T e3) ) .
Conditionals ar e automatically optimized i n t he sense t h a t
I F e l THEN e2 ELSE
I F e3 THEN e4 ELSE e5
becomes
(COND ( e l e2) (e3 e4) ( T e5))
r at her than
(COND ( e l e2) ( T (COM) (e3 A) ( T e5) ) ) ) .
The nested form
I F e l THEN
IF e2 THEN e3 ELSE e4
ELSE e5
i s permitted and becomes
(COND ( e l (COND ( e2 e3) ( T e4))) (T e5))
Note t ha t all of t he predi cat es i n a COND msy evaluate t o NIL, i n which
case NIL i s returned a s t he value of t he condi t i onal . ( c f . Ref. 3 f or
further details) .
I N DO
E. <FOR expression> : : = FOR i i de nt i f i er > EON] <expression> (COLLECT 1
<expre s s i o 0 [UNTIL <express ion>]
This i s t he f i r s t of t he MLISP "meta-constructs," a l l of which ar e
i t e r a t i on expressions cl osel y resembling ALGOL st at ement s, I t s eval uat i on
w i l l be i nformal l y i l l us t r a t e d through an example:
\
For I I N e l DO e2 UrJTIL e3.
Evaluation :
V + NIL (NOTE : V, L,X are temporary var i abl es)
L +val ue ( e l ) (NOTE: e l should eval uat e t o a l i s t )
i f NULL (L) t hen I ?ROG~( I + NIL, RETURN (v))
I + CAR (L)
L +CDR (L)
*.A. V +val ue (e2)
*** X +val ue (e3)
**+w
i f X f NI L t hen RETURN (v)
GO TO A
It may be seen t ha t t he cont r ol var i abl e I "st eps through" t he l i s t
L which i s t he value of e l ; i.e., I becomes successi vel y CAR(L) , CADR(L) , . , . .
If t he UNTIL condi t i on i s omitted, t hen l i ne s w* and *w* a r e omitted.
If ON r at her than I N i s speci fi ed, then l i n e * i s replaced by I + L;
i.e., I becomes successi vel y L, CDR ( L) , CDDR ( L) , e t c . I f COLLECT
r at her than, DO i s speci fi ed, t hen l i n e ** becomes V +- V APPEND val ue
Expression e l i s eval uat ed onl y once. Expressions e2 and e3 ( i f e3
i s present ) ar e eval uat ed each time through t he loop. Both may be funct i ons
of t he cont r ol var i abl e ( I i n t he above example) .
L
The use of COLLECT i s one of t he most powerful f eat ur es of MLISP.
With it, l i s t s of a r bi t r a r y complexity may be assembled wi t h l i t t l e e f f or t
( see F, G,H) . For example, t he val ue of
FOR I I N ' ( (GOOD . 16) BAD (GOOD . 58) ) COT,LFCT
I F I EQ 'BAD THEN NIL ELSE <CDR (I)>
i s (16 58) . See WHILE-COLLECT (P. ) f or anot her example. Note t ha t
<CDR(I)> i s used r at her than CDR ( I ) ; <CDR (I)> i s t r ansl at ed i nt o
(LIST (CDR I)), so t ha t t he APl?ENDted list w i l l be a l i s t of t he CDR's,
1 as desired.
T t should be mentioned t ha t t her e i s never any danger af MLISP confusing
i t s temporary var i abl es wi t h user-defined vari abl es. The temparary var i abl es
speci f i ed above were j ust examples; i n r e a l i t y MLISP uses speci al charact er
s t r i ngs which are i l l e g a l i de nt i f i e r s i n the MLISP language.
F. <FOR expressiorP : := FOR <i dent i f i er > ( :g] <expression> TO <expression>
[BY <expression>]
} <express ion> [UNTIL cexpres s i o ~ ]
~ C O L , ,
This i s si mi l ar t o ( D) above. Again by example:
FOR I := el t o e2 BY e3 DO e4 UNTIL e5
Evaluation:
V + NIL (NOTE: Again V, UPPER, INC, X are tempories)
I + value ( el )
UPPER + value ( e2)
3c INC + value (e3)
A: i f I > UPPER then PROG2 ( I + NIL, RETURN (v))
~ CJ C V + value (e4)
SC~CJA X +- value (e5)
.
-w*+
i f X f NIL then IlETURN (v)
I + 1 + I N C
Again, i f t he UNTIL condition i s omitted, l i ne s w* and *** ar e
left out . If t he BY speci f i cat i on o f t he increment i s omitted, l i ne *
becomes INC +- 1 . I f COLLECT r at her than DO i s specified, l i n e becomes
V + V APPEND value (e4) .
Example: FOR I := 1 TO 10 COLLECT <PRINT (I)> W I L (1/4) = 1
would pr i nt onto t he output device
and r et ur n (1 2 3 4) as i t s value.
} <expression> UNTIL <expression> G. <UNTIL expressio* ::= ECOLLECT
For t he case DO e l U'NTIL e2, eval uat i on i s as fol l ows:
* A: V +-value ( e l )
X +- value (e2)
if X NIL t hen RETURN (v)
go t o A
Example:
DO M +- READ ( ) UNTIL M EQ 'STOP would read successi ve s-expressi ons
from t he i nput device u n t i l "STOP" was read. The val ue of t he loop would
then be "STOP" al so, si nce M +- READ ( ) i s t r ans l at ed i nt o (SETQ M (READ))
which has as i t s val ue t he l a s t t hi ng read.
I f COGLECT r at her t han DO i s speci fi ed, l i ne * becomes V +- V APPEND
value ( e l ) .
DO
H. q HI L E e xpr e s s i o0 : : = WHILE <express i or 0 [COLLECT ] <expression>
For t he case WHILE e l DO e2, eval uat i on i s as follows:
V +- NIL
A: X +val ue ( e l )
i f NOT X t hen RETURN (v)
JC V + value (e2)
go t o A
If' COLLECT r at her t han DO i s speci fi ed, l i ne * becomes V + V APPEND
value ( e2) .
The only di fference between t he UNTIL expression and t he WHILE
expressi on i s t ha t i n t he WHILE expressi on t he t e s t f or t he t ermi nat i ng
condi t i on i s made f i r s t , while i n t he UNTIL expressi on it
i s made second.
As an example of $he power of t he COIJLECT var i at i on of t hese expres-
si ons, consider:
WHILE NOT ( (A + READ ( ) ) EQ 'STOP) COLLECT <CADR(A) >
If t he i nput f i l e cont ai ns a sequence of l i s t s i n t he form (DEFPROP
<funct i on name> <lambda def i ni t i on? <i ndi cat or>), which i s a ~i t andard form
f or funct i on def i ni t i ons, t hen t he above WHILE expression would assemble
a l i s t of a l l t he funct i on names i n t he f i l e u n t i l t he atom "STOP" was
encountered. Concise s-batements of complex expressi ons such as t h i s i s
one of t he primary purposes of MLTSP.
I. < l i s t expression> ::= < <ar gl i st > >
This const ruct i s t he MLISP equi val ent of t he LISP LIST expressi on;
a , B , C > i s t r ansl at ed i nt o (LIST A B c), < > i nt o (LIST) = NIL, et c. Note
t ha t LIST(A,B,C) i s a l s o t r ansl at ed i nt o (LIST A B C) ; G, B, C> i s t he
shar t er not at i on. A CONS B CONS C CONS NIL would al s o have t he same e f f e c t ,
As mentioned i n t he i nt roduct i on, it i s a general propert y of MLISP t hat
most const r uct s msy be expressed i n sever al ways. This redundancy i s
del i ber at e; it f a c i l i t a t e s t he w r i t i ~ g of programs by r el i evi ng t he user
from f i ndi ng t he - one cor r ect expressi on,
Arguments i nsi de t he l i s t bracket s may be any a r bi t r a r y expressi on
( cf . J below). This i s al s o t r ue of funct i on c a l l s ( cf . L below),
Example :
CONS B, <MI N (3 + I, J ) , N I P , LAST (J)>
goes t o
(LIST (CONS A B)
(LIST (MIN (PLUS 3 I)J) NIL)
(LAST J)
1
An argument l i s t i s one or more expressi ons a r f unct i onal arguments
separat ed by commas. Si nce an expressi on may be empty, an argument l i s t
may be empty.
A s peci al case i s made of t he f unct i onal argument i n order t o
permit a r bi t r a r y LAMBDA expressi on$ t o be i ncl uded i n an argument
l i s t . The sharp symbol (#) i s t r ans l at ed i n t o LAMBDA^', t he i d e n t i f i e r
l i s t i n t o the LAMBDA-bound var i abl es , and t he expressi on i n t o t he
LAMBDA expressi on. Example:
FOO (# A,B: IF A EQ B THEN T ELSE A) goes t o
( FOO (LAMBDA ( A B) (COND ( ( EQ A B) T ) ( T A ) ) ) ) .
Funct i onal arguments which ar e passed by name may be
t r e a t e d l i k e any
ot her f'unction call ( see L below). Example: FUNCTION (CAR). Here
CAR i s a f' unction which i s bei ng passed as a f unct i onal argument by
name. See t he LISP 1 . 5 Manual ( ~ e f . 2 ) f or f ur t her information on
f unct i onal a~gument s.
K. <::tring> : := "<any sequence of char act er s except " > "
Strings are a special MLISP data form (see Part IV).
Strings are
stored as a list of the individual characters in the string; for
example, "THIS IS A STRING!" is stored as (T II I S / - I S / - A /-
S T R I N G ! ). he symbols / - represent the blank character.) With
the MLISP-defined atom DBQUOTE -- defined to be "--and the MLISP string
function CAT (see Part IV), double quotes may be inserted into strings;
e. g. , "TKLS STRING CONTAINS" CAT DBQUOTE CAT" A DOUBLE QUOTE".
In MLISP the function names are brought outside the parentheses,
and the arguments, if there are more than one, are separated by commas*
Examples :
CAR (A) is translated to
PLUS (1,2,3)
FUNCTION(CAR)
APPEND (A CONS B,C CONS NIL)
(CAR A)
(PLUS 1 2 3)
(FUNCTION CAR )
(APPEND(CONS A B)
(CONS c ML) )
Functions having exactly two arguments may alternatively be used as
infix operators. For example, CONS(A,B) and A CONS B are equivalent,
both being translated to (CONS A B).
#
M. <function definitior3 : := <identifj er> [ z) [,]<identifier list>:<expressiorS
This is the mechanism for defining functions. The identifier is the
function name. If the sharp (#) is used, the function will be an MPR; if
the star (*) is used, it will be an FMPR. In either case the translation
is "ISIMBDA." The identifier list specifies the LAMBDA-bound variables,
and the expression is the LAMBDA expression. Examples:
MI N := # A,B: IF A LESSP B THE3J A ELSE B;
SMALLEST := *L:
46 FINDS THE SMALLEST WE3AMONG ITS ARGUMI3NTS %
BEGIN NEW X,Y,I;
IF NULL (L ) THEN RETURN (NIL) ;
X := EVAL (CAR ( L) ) ; Lt CDR(L);
FOR I IN L DO
END ;
The first function is an EXPR with two arguments that returns the smaller
of the two. The second function is an FEXPRJhat takes any number of
arguments and returns the samllest one. Note that in the second function,
since FEXPR's do not evaluate their arguments? the arguments have to be
evaluated explicitly by calls on EVAL.
The second function illustrates several features of MLISP:
(a)
The phrase tetwee? percent signs ($) is a comment.
( b)
The BEGIN-END bl ock specifies it to be a PROG, with PROG
variables X, Y and I.
( c )
The RETURN expression is used to return a value for the
function.
(d)
The FOR loop steps through the list L comparing each
element to the current smallest element and making the
appropriate change.
( e) x := Y;
X +Y;
SETQ
These a r e a l l equi val ent , and may be used i nt erchangeabl y ;
a l l ar e t r ans l at ed t o (SETQ X Y) .
When a f unct i on i s defi ned, one of t hr ee t hi ngs occurs. Ei t her :
(1)
The f unct i on def i ni t i on i s immediately added t o t h e pr oper t y
l i s t of t he f unct i on name, under t he appr opr i at e i ndi cat or
(MPR o r FEXPR).
( 2 )
The f unct i on def i ni t i on i s GRINDEF'ed ont o t he s el ect ed
out put f i l e ( cf . Par t I), i n t he cor r ect form f o r i nput
i n t o t he campiler.
( 3 )
The f unct i on i s immediately compiled ont o t he out put devi ce
wi t hout f ur t he r ado.
Al t er nat i ve (1) occurs i f t he second and t h i r d arguments t o t h e MLISP
f unct i on ( cf . Par t I ) a r e absent . Al t er nat i ve ( 2) occurs i f t he t h i r d
argument i s NIL; a l t e r na t i ve ( 3 ) , i f it i s T. MLISPC must be used
f o r a l t e r na t i ve (3). I n any case, a f t e r t he f unct i on has been defi ned,
i t s name i s pr i nt ed ont o t he t el et ype.
Funct i on def i ni t i ons a r e not considered t a be execut abl e expressi ons
a t runtime, and, a f t e r one of t he above t hr ee a l t e r na t i ve s has been
executed, NIL i s r st ur ned a s t h e i r t r ans l at i on. Aft er t he e n t i r e MLISP
program has been t r ans l at ed, a l l non-NTL expressi ons a r e col l ect ed i n t o a
PROG and a new f unct i on named RESTART i s defi ned, wi t h t he PRE a s i t s
def i ni t i an. For t h i s funct i on, al s o, one of t he above t hr ee a l t e r na t i ve s i s
executed. The RESTART f unct i on provi des a convenient means f o r r e- ent er i ng
MLISP programs. Typing (RESTART) w i l l begin execut i on of t he program,
s t a r t i n g wi t h t he f i r st execut abl e expressi on. An example may c l a r i f y
t h i s . Suppose t he MZISP program i s
BEGIN IVEW X;
MI N := # A,B: IF A LESSP B THEN A ELSE B;
This creates the following property lists:
N. <assignment expressiorP : := iidentif ier> r) <expressiorO
Either the colon-equal or left arrow symbol may be used in assign-
ment expressions. Both translate into SETQ. The following all translate
into (SETQ A (PLUS B c)) :
A : = B - + C
A + B + C
A SET& B + C
SETQ (A, B + c).
The author prefers the left arrow as being the clearest.
Multiple assignments are permitted, since assignments are thern-
selves expressions:
X c Y t Z t $
is translated to
(SETQ x (SETQ Y (SETQ z j d ) ) ) .
The value of an assignment expression is, as in LISP, the value o f the
expression on the right; this should be clear from the LISP translation.
0. Ci nf i x operat or> : := *\ **\ - \ / \ +\ &\ @\ =\ <i dent i f i er >
The above symbols a l l have pre-defi ned meanings i n m S P , $0
provi de a conci se short-hand f o r c e r t a i n commonly-used LISP functions.
The meanings ar e:
= EQUAL
* TIMES
** EXPT
- DIFFEWNCE
/ QUOTIENT
(onl y i nt eger exponents a r e al l owed)
(MINUS i f used as a unary (prefix) operator)
+ PLUS
Thus A TIMES B and A*B are equi val ent , f o r example. Also any ot her
f unct i on of two arguments may be used as an i n f i x operat or. Thus t he
MTN f unct i on defi ned i n ( M) above may be cal l ed ei t her by MI N (A, B) or
1
A MI N B. Thi s hel ps t o reduce f ur t her t he number of parent heses and
f r equent l y improves t he r e a da bi l i t y of a program.
There are two other MLISP-defined oper at or s: NEQ and NI3QIJAL.
A NEQ B i s t he same a s NOT (A EQ B) , and A NEQUAL B i$ equi val ent t o
NOT ( A=B ) .
P. Cp r e f i D : := + \ - \ NOT ( NUL L I AT OM
These are unary oper at or s having t he fol l owi ng t r ans l at i ons :
t-x 3 X
-X 3 (MINITS x)
NOT X 3 (NOT X)
m z x * ( m ~ x)
ATOMX 3 (ATOM X )
The l a s t t hr ee may al s o be cal l ed wi t h parent heses around t h e i r argu-
ments, l i k e any ot her funct i on: NOT(X), NULL(X), ATOM(X). Using them
a s a pr ef i x operat or, however, hel ps t o reduce t he number of parent heses
i n t he program.
Q.
<i dent i f i er > : := <l et t er > [<any sequence of l e t t e r s or di gi t 01
A l l i de nt i f i e r s must begin wi t h a l e t t e r . Let t er s a r e considered
t o be any of t he 26 l e t t e r s i n t he alphabet or t he exclamation poi nt (! )
symbol. The exclamation poi nt i s included t o enable t he user t o form
unusual i de nt i f i e r s ; e.g., !SYSTEWl . Examples of i de nt i f i e r s ar e A,
AVERYLONGSTRING , K52BJE1, HELP!, ~$$$l. Limits as t o t he l engt h of
printnames, et c. ar e t hose of t he underlying LISP processor ( see Ref . 3 ) .
Two t ypes of numbers a r e permi t t ed i n MLISP, r e a l and i nt eger .
Exponents may be speci f i ed vi a t he " operat or; e.g., 1$ " 2. The
base of a l l numbers i n MLISP i s Examples of numbers ar e
-
1
lfl
This l a s t get t r ans l at ed i nt o NUS (EXPT 9876.54321 6) ) .
Recal l t ha t onl y i nt eger exponents ar e allowed, unl ess t he user wants
t o defi ne hi s own exponent funct i on.
Fi nal l y,
s-expressions may be quoted usi ng t he si ngl e quote ( ' ).
Whereas t he LISP user wr i t es (QUOTE <s-expressio+), t he MLISP user
wr i t es ' <s-expression>. Examples!
(QUOTE A)
(QUOTE (A B c))
(QUOTE(A. B))
(QUOTE (A (B C) (E F)
G ) )
I V SPECIAL CONSTRUCTS - DATA STRUCTURES
Sever al of t he s pe c i a l MLISP cons t r uct s - t he i t e r a t i o n expr essi ons -
have al r eady been descri bed. These were desi gned t o s i mpl i f y t he wr i t i ng
of complex expr essi ons, i n addi t i on t o el i mi nat i ng GO t r a n ~ f e r s and
f ur t he r c l a r i f yi ng t he fl ow of cont r ol . It shoul d be evi dent by now
t h a t none of t he r ecur s i ve power of LISP has been s a c r i f i c e d; r a t he r ,
MLISP ext ends t h i s power, i f we def i ne t he "power" of a language t o be
t h e ease wi t h which complex r out i nes may be wr i t t en,
The da t a s t r uc t ur e s of MLISP ar e, of course, t hose of LISP: symbolic
"atoms1' , numbers,and l i s t s t r uc t ur e s . I n addi t i on, MLISP defi nes
st ri ngs--sequences of char act er s encl osed by double quot es (")-
a s an i nput / out put or i ent ed dat a form. St r i ngs ar e s t or ed i n t e r n a l l y
a s l i s t s of t he char act er s i n t h e s t r i ngs . Any LISP-defined char act er
except double quot e may appear i n a s t r i n g ; double quot e may be added
wi t h t h e MLISP-defined atom DBQUOTE. Cer t ai n s t r i n g mani pul at i ve
f unct i ons a r e defi ned i n MLI$P. These f unct i ons a r e CAT, PRINSTR,
STR, STRING, and SUBSTR.
CAT - Concat enat i on, a f unct i on of two arguments which may be
e i t h e r s t r i ngs o r atoms.
If t hey a r e bot h s t r i ngs , t he val ue i s t h e i r
concat enat i on. I f one or bot h a r e atoms, t he printname of t he atom
i s f i r s t made i n t o a s t r i n g and t hen concat enat ed.
PRINSTR - A f unct i on of one argument, a s t r i ng. It p r i n t s t h e
argument exact l y a s it appears ont o t he cur r ent out put devi ce, ending
t h e l i n e wi t h a car r i age r et ur n, Value i s NIL.
STR - A f unct i on of one argument,
an atom. Value i s a s t r i n g of
t h e atom ' s p r i n t name,
STRING - A funct i on of one argument, a l i s t . Value i s a s t r i ng of
a l l t he charact ers i n t he l i s t , i ncl udi ng parent heses and blanks.
SUBSTR - A funct i on of t hr ee arguments. The f i r s t argument i s a
s t r i ng. Value i s a subst ri ng of t he s t r i ng. The second argument i s
t he s t a r t i ng posi t i on of t he subst r i ng counting from one. The t hi r d
argument i s t he number of charact ers t o be ext r act ed,
These funct i ons w i l l be i l l us t r a t e d by examples:
"THIS IS A CAT "STRING" = "THIS IS A STRING"
"THIS IS A " CAT 'STRING = "THIS IS A STRING"
STR (' STRING) = "STRING"
STRING ( ' ( A ( B C ) D ) ) = "( A ( B C) D)"
SUBSTR ("THIS SS A STRING", 6, 4) = "IS A"
PRINTSTR ("STRING" ) w i l l pr i nt STRING
PRINT ("STRING") will pr i nt (S T R I N G)
PRINTSTR ( "STRING" CAT DBQUOTE ) w i l l pr i nt STRING"
These funct i ons provide t he mechanism necessary t o cr eat e, add t o,
fragment, and pr i nt st r i ngs. This mechanism allows t he user complete
cont r ol of hi s output st at ement s.
There ar e two ot her MLISP-defined funct i ons which ar e s t r i ng r el at ed
but which apply t o ar bi t r ar y l i s t s as well: PRELIST and SUFLIST.
Both t ake two arguments. The f i r s t i s a l i s t or s t r i ng; t he second
i s an i nt eger . Thei r values w i l l be i l l us t r a t e d by example and by
def i ni t i on.
PRELIST ( ' ( A B C D E) , 3) = (A B C)
PRELIST ("THIS IS A STRING", 9) = "THIS IS A"
SUFLIST ( ' ( A B C D E), 3) = (D E)
SUFLIST ("THIS IS A STRING", 9) = " STRING"
For a l l l i s t s L and f or a l l i nt eger s N,
PRELIST ( L, N) @ SUFLIST ( L ~ N ) = L.
PRELIST and SUFLIST are designed t o f a c i l i t a t e t he mani pul at i on of L i s t s .
Thei r MLISP def i ni t i ons ar e:
PRELIST : = #L,N:
IF (N=$) OR WLL(L) THEN NIL
ELSE CAR(L) CONS PRELIST (CDR(L) , N-1) ;
SUFLIST := #L,N:
I F (N=$) OR NULL ( L) THEN L
ELSE SUFLIST (CDR(L), N-1);
To f ur t he r si mpl i f y list handl i ng, ni ne " f i el d" f unct i ons ar e defi ned
i n MLISP: F1 through 3'9. F1 r et ur ns t he f i r s t element i n t he l i s t which
i s i t s argument, F2 t h e second element, e t c . Examples:
F ~ ( ' ( A B c D E ) ) = A
F ~ ( ' ( A B C D E)) = I3
F~('(A B C D E)) = E
~6(' ( A B C D E ) ) = undefined.
These f unct i ons were added on the theory t hat i n manipulating t he, say, s i xt h
element i n a l i s t , it i s cl ear er t o wr i t e F~( I ) r at her t han CADR(CDDDDR(L)).
*, < n ~ . , ~ L L 1 - 1 1 . I O L L I . I , L I r n u u , V M ~ I H W L L J P K L H U I U ~ * I I ~ I H L L T
1 ~ ' r I T I k L I t F J 7 0 ' Q I L ' , %
FOk I 111 L 30 V * I CONS V ;
R t T b Y N ( V ) ;
t h J ;
f i t \ / t c > F 4 : = k L :
h T C l S IS A;.; i k P 2 , USES A , ~ H I L E LOPp, %
X ~ l - I L L T t i t t ? E ! \ ' ; TI LL ~ L J ~ I E : ~ ( I V ~ ~ L t F T I N * L , * THL PHOGL I S EXECUTED, X
b F t i I l u ' JEh V ; SI J ECI AL V ;
h H I L E L L J O PROGi ' t V + CAW( L ) CONS V, L * C Q H I L ) ) ;
K t T U u " ( V ) ;
E h i l :
f i t \ t & b F 5 : = # L :
1/, TClS 15 AIJ EX" 9, USES A U O- U U T I L LOOP, X
x i b t PtIOGZ I S Ef F CI I T F S 1 l i J T I L ' L ' I ? N I L , %
I F h dl -L L Tt i Ek > J I L FLSL
HF GI I L P d E W ' 1; S P E C I A L V;
c C P*dG; i ( L * C A S ( L ) CObJS VIL * C r l R ( L ) ) U N T I L NIJLL L i
Rbl UHW ( b j ;
E ~ u ;
f i t v t F S F 6 : = +L:
% I k I S [i A ~ ~ O T Y E Q FEXPH; TI I E AECUMFNTS ARE, NUT EVALUATED, X '
"/;,l-lq I S L F SS GE" \ I Tf ?AL- T HA N T H t OTHFR FUNCTI ONS; I T Cl I LC NOT WORK
FUR L 1\10 GF LFSJ(; TH > l dk?, Ir
A i T w F V b I ? , I T IS IQCLUDFD A', AN EXAMPLE OF A FOR- LO[ j P USI NG A
+ \ u h l C Ql r L l I ~ C L I ~ Y F N T , lj/.
I F n u L L L ~ 1 1 t h ~ J I L FLSE
~ F , J T 4 ' L E N I , V ; S P F C I A L I l V ;
6 U q I * l 7 0 D O PRgG2( \ / * CAR( [ - ) CONS V t L * C O H ( L )
11. r Tj L NU1 L L ; % T d I S ' U N T I L ' CONDI T I ON STOPS THE FOHwLOOP I F
* L ' COYTAI NEn FEWER THAU 1@0 ELEMENTS, %
~ ~ T J K I \ ( v ) ;
L ' ' ;
x 11 I S I MPOPTANT TO NOTE T HAT I F ANY TOR- LOOP I S HAL T ED BY THE ' UNTI L'
C C N r I T I r l N BFCOYI NG TFt UE, THE CONTROI V A R I A d L k I S NOT RESET T o ' NI L ' ,
T t t . L ( l L Tt <OL V A 4 I A H L E I S S t SET I F AND ONLY I F THE FOR- LOOP HALTS
i f ' k I L r ( i , E , UOT !7UE TO TNt : " JNTI L ' C ON D I T I ON ) , I N THE ABLI VC CASE,
* - - i * . ~I " A~. , $ HAT I J F O ~ T Q I ' ~ Tl l E LELIJtTld OF THE L I S T ' L ' - - I N THE
I t - t a ? V G L I I ~ OF ' I * - - A S r 5111E EFFECT OF REVERSI NG i T .
I - I , t t C I F I C A L L Y 3ESIl;r.IEU 10 F A C I L T T A T F S J CH ' SI MUL TANEOUS'
FE + F o v u : . r' F OF i l F' FShTI O115, :<
9
< t
RE v E f i S E 7 : = * L ; HEVERSEJ A( L , M( L ) J
% AhUTHER kaY OF WRI T I NG kEVgRSEb, Y
% T k l q DOES NOT HF13111RIE AI\Y BE~C;INIL:~O, NEk u L C&ARATI ONS, OH RETUkN
STATEMF- NT, X
% I T ALSO PRESERVES THE L t N G T H OF ' L * I N THE CLOAAL VARI ABL C ' L EN' , X
f i t b K S c / A : = # C , b :
I F h U L L L THEN N I L E&SL
F f H L E t v + l 1 0 $ E B 0 0 0 0 2 ( V r CAM( L ) CONS VIL * S O R t C ) ) U N T I L NULL L i
CL2 : = k 4 , d : a ;
% ' r U 2 ' 13 L I K E FF(GC;L, FYCEPT T t i A t n02 HETURNS THC VALUE Of I T 9 F I R S T
A k C J MK N T , %
C
~ ~ # t b # ~ l t 9 ~ # t # f k # # d d r t # 1 # # 4 # # # ~ # d # ~ # ~ k # # # # # # # # # # # # # ~ # # # k # # # # # ' # # # # # # # # # # # # %
% u b # i i ~ # # ~ & u ~ a b ~ # ExLCu' Fl Oh B r G l N S M E R E Y # P # # # ~ # # # Y # # # ~ x
~ P a # b u ~ ~ ~ n n ~ a ~ l ~ b a # k r ; n ~ a n t r u ~ 1 1 # ~ # 4 4 ~ # d ! ~ n # # # ~ # ~ # # # ~ # ~ # ~ # ~ # # ~ U # f l # # # # # ~ # # # ~ %
C1
L k P R L T S T * ( 4 EVL v Gi F 1 qUVt . Hki E2 H E V t R S E 4 HL VEHSE5 ) ;
I F A r N L l S T + ' ( H l Vr 2 5 E3 WEVE' <S[b HEVFRSE7 ) i
% dFAD 114 PKST L I S T S I J N T I I THE ATOM ' ST OPt I S ENCOUNTEf I ED %
P K 1 4 1 h T ~ ( " T Y k J E A L I S T TO UE t 4 EVt i RSEnow) ;
hl - 11 t. (L. * 1 : FA3 ( ) ) YE0 ' S l OP 0 0
b F ~ , T l u J E %~ I ' UNCLI ST, FOhl CNAMk , F U L J C i S P E C I A L F' VNCL I S' r , F' UNCNAME, FUNCi
T t F ; F . 4 1 ( ) ; % S K I P A LI NE. I N THE OUTPUT %
i h I J T S T ~ ( ' ~ T Y E T E S T 6 13.1 IS " CAT S T R I N G ( ( ) ) ;
*, C(JL. LTLT 1;)f;i;THf:R TbtF: PI I LCTI QN L I A M E S APPL I ED TO THE T EST L I S T %
T ~ J I J U L I S T c F I ) ~ F I I N C V A ~ ~ . I J t X P R i T S T Ct l LLEOT <<FUNCNAME, <' UUOTE, L) ) ) r
T d ' , c ~ [' T c F IJ',C'I,.IST ,.I t 33 FU-iGNAbl I N FEXPRL [ S T COLCECT (F' UNCNAME CONS 4);
it!, + t 4 ; X RESET THC L I S T LFbj GTH, X
'; FVALc t ATE ALL OF Td E f l l f \ l : TI Ql y S L I I TH TI.IF. TCST ARGUPENT X
Fbk t i Ji 4C I I L F UrJCL I ST 30
T t f - I \! X F N STAQT;
P k l h l T ( L ; ~ ~ ( F I J L C ) ; % P R I N T OUT THE FUNCTI ON NAME %
ST AF T * T I Y F O ; X ' T I M F O P YIELOS THE CURRENT T I M&
I N MI L L I SECONDS X
P r c I h T ( t ; v A L ( F u : . ~ c ) 1 ; % EVAL I I ATE THE F UNCT I ON X
P H 1 ? , T ~ ( T I M L 0 - S T P 4 T ) / 3 . 3 C I v j e / I ) ; X P R I N T THF T I ME dEQLJI PEQ %
~ U I K T ~ T I ~ ( ~ S F C \ ~ ) ;
i t 5Pki ( 1 : X S K I P A LI NE. I N THE ULJTPtJT X
F ;
? Tu; LLt dGTH ' LE. 4' I S u b T A l V t 9 Fr+DY HEVt PSE7 . Z
; n l \ l S T h ( " T H f CC' JCTM OF Tqr l C $ T LIST k A S " CAT L EN) ;
T t G P * I ( ) ; T E F P H I O :
F K I , ~ ~ S T K ( " T Y I ' F 4NCl THFd L I S T T 3 JF REVLASEU, 17H ' S T O P 4 " )
t 4 J ;
" / PLY I. l c P 11Hb!;H4'1, I N T O kbl1C1-I T t i I S ML I S P PdOCRAM ( S THAPI ' SLATkD, I S
LI sTt - f : T' 4E FOL1.3dING PACYS, I T M A S YEF a I F H I N T ~ I J USI NG A
j; A i \ t O- c8r - ~h 1 T T W F' JI J[ : TI ON CL\ LCL' ? ' F R I FJDEF: ' Ah1 S- F' XPRESSI O. \ I UN-CRUMCHEH,
~h T h F +AGE! ; FOL L OWI XC THAT I 3 l'HF FOMPCETE T F L h T YPF L I S T I N G O f A PRUt RAM
k l '". '4
f- :\ r ,
( u F F F d r V L X P H L I S T T S P E C I A L )
( L EFEHCP F E X P R L l S T T S P E C I A L )
( CEFFdCf - ' L t N T S P E C I A L )
( L F F F HCV L T S P E C I A L )
( C r F C d C P 1 7 S P E C I A L )
( r ; EFFFr F L T S P k C I A L )
( :FF Fr ( TP b ON L L I S T 7 S P E C I A L )
(,FFF: drt' F LI ' I TFJAMF T S D L C I A L ]
: ; ckr < - r ' F, I ' JL T S ? E C : r l )
' - t - . - , t?
, ) ; t ', t - St.:& L FJII.) )
, *;. I t
(,F F r- k r Vl ' kSkl A
( L A V ~ ~ A ( L . L L ) ( COh l ? ( ( N U L L L ) L L ) ( T ( REVL RSEl A ( CDR ( CONS ( CAR L ) L L ) ) ) ) )
F XFi i
( -; c c < r t .,F 8 4 + SF;
, : r b ',",A : L ) ( dh417 ( ( J;I?C 1.1 ~ I L ) ( T ( APPEND ( RLVLRSE2 ( CDR L ) ) ( L I S T ( CAR L ) ) ) ) ) )
, L - r >
30
( OE F F Y CV REVERSES
( L A V Y r A ( L ) ( PROC ( I V ) ( : CORQO ( QUQTF I) T 4 ( QUOTE ( S E T 0 V ( CONS I V ) ) ) N I L ) ( RCT URN V ) ) )
F E X P F
( CE F F HCP HFVEHSE4
( L A C U C A t L )
( P WC ( \ r ) ( : WHI LSI ) O ( Q ~ J O T E 4 1 (OIJOTE I PROG? ( SETQ v ( c o w ( C A R L ) v ) ) ( S E T Q L ( CDR L ) ) ) ) ) ( RETURCJ v ) ) )
E X P H )
( CE F F HCP t dFVERSE5
( L A C Y ? A ( L )
c c c m ( ( N U L L L ) N I L )
( T
( P R OG ( V )
( : D O U N T I L ( QOQTE (PRWCZ ( S f T Q V ( CONS ( CA R L ) V ) ) ( $ ETQ L ( CDR L ) ) ) ) ( O U Q T ~ ( N U L L L)))
( R E T U R d V ) ) ) ) )
E I F H )
( GEF F d r P RE V E RS E 6
( L A V U C A ( L )
cccur ( WUL L L ) UIL)
( 1
( F ROG ( I V )
( : F ORL OOP ( QUOTE I )
( QUOTE ( 1 0 1Bn, 1,))
T
( QUOTE ( P H O G 2 ( S E T 9 V ( CONS ( CAR L ) V ) ) ( S E T 0 L ( CDR L ) ) ) )
( QUOT E ( N U L L L ) ) )
( RETI JRW V))))l
F L X P R )
( GE F F HCF RFVE' RSE7A
( L Ab ' d r A( 1 . k )
( C c N r ( ( P i U L L L ) Y I L )
( T
( : F UHLUOP ( UUD I'E L C N )
( n u o T c (1, i u a , 1, ) )
T
( QUOT E (002 ( S t T Q V ( CONS ( CA R L ) V ) ) ( S f T Q L ( CDR L ) ) ) )
( QUOTt . ( : NULL L 1 ) ) ,
E X F M)
( GEFFt t CP l ~ 0 2
( L A P UCA ( 4 R ) A )
EXF H)
( L T F F I ~ C ? d f $ T A R T
( L AP d ! : A u I C
( PG[ j C ( L x P H L I S T F S x P R L I S T CCh)
( S CT O E X P R L I S T ( Q u O T t ( REVERSCI RE V E RS E 2 REVERSE4 R E V S R S S 5 ) ) )
( S E T O F E x P R b I S T ( QUOT E ( R L V t R S F 3 REVERSE6 R E V L R S E 7 ) ) )
( P Y I N T S T H ( QI I f JTE ( T Y P E / A / L I S T / T 0 / 8 E / R E Y E R $ E D / , I ) )
( : r l HI I . E00 ( QUOTE I NEr J ( S E T I I L ( H E A D ) ) ( QUOT E S T O P ) ) )
( Q V O T t
( P R ! ) i ( F VNCC IS1 611NPVAME F UWC)
( TEHPR I 1
( P q I N T S T h ? ( C A T ( QUOTE ( T Id E / T E 5 T / I,, I S T / 1 S / ) ) ( S T R I N G L)))
( SCTi J F IINGL I ST
( : F O R L I q T ( 0 4 UT E F UNCNAME)
T
EXPRL I E T
( QUOT E ( L I S T ( L I S T FUNCNAME ( L I S T ( QUOT E QUOT E) L ) ) ) )
N I L )
( S E T Q F UNCL 1 3 7
( 4PI ' t P; O FUNC:L I S T
( : F O R L I S T ( QUOT E F UNCNAME)
7
F E X P R L I S T
( QUOTE ( L I S T ( CONS FUNCNAME L ) ) )
V I L ) ) )
! ? K T 7 kt . 4 3 . )
( : t-oRI)c c JJn r r FUNC
I
1 '1'4r-L I S T
i .:jPTr
( P F J C ( S T A R T )
( P R I N T (FAR F U N C ) )
( S E T Q $ T A RT ( T I M E ) )
( P R I N T ( E V A L F UNb ) )
( P R I N T ( QU OT I E N T ( D I F F E R F N C E ( T I M E ) S T A R T ) &B98, i J) )
( PRI NTSTR ( QUOT E ( S E c s ) ) )
( PR I NTSTH
( C A T ( Q U O T E t T H t / L E N G T H / O F / T H E / T E S T / b I S T / W A S / ) )
L E N ) )
( TEHPR I )
( TEHPR I
(PR 1 NTSTR
( QUOTE
( T Y
P
C:
/
4
N
0
7
H
E
H
/
L
I
?
/
T
0
b
I 3
F;
/
I?
L
v
E
H
3
f
3
I I
/
0
f4
/
t
S
7
u
I-'
' ) ) ) ) I ) ) )
*
REVERSE1
REVERSE 1 A
REVERSE2
REVERSE3
REVERSE4
REVERSES
REVERSE6
HEVEeSE7
REVERSE7A
DO2
tiESTAr?T
*
6.68800BQ SECONDS COMPILATION TIME
1281.8181 LINES PER MINUTE COMPILATION SPEED
NO ERRORS WERE DETECTED
NO FUNCTI ONS NERE REDEFINED
TYPE A LIST TO BE 3EVERSED.
* < A 3 C 0 E l
THE TEST LJST IS ( A B C O E)
REVERSE1
CE O C B A )
@. 32999999E- 1 SECS
REVERSE2
CE 13 C 13 A)
G~~.3%999999E- 1 SECS
AEVE2SE4
(E I) C i3 A)
0.32999999E-1 SECS
4 EVEd S E5
CE Il C B A )
Q. 33Q99999E- I SECS
8EVERSE3
( E D C B A )
0032999999E- 1 SECS ,
'I'HE TEST LIST I S NIL
dEVERSE1
N I L
flo 16999999E- 1 SECS
dEVERSE2
NI L
SECS
"I EVERSE4
NIL
OoC7r SECS
ZEv EHSE5
NIL
0 0 1 6 9 9 9 9 9 9 E - 1 SECS
dEVEHSE3
NI L
P o l J SECS
!ZEVEASE6
NIL
?lo 16999999E- 1 SECS
TYPE ANOTHER LIST TO BE 2EVEt3SEDs 013 ' S T O P '
* < ~ H C t ) E k ' G ~ I I J K L M N O P ~ d $ T U t + d X Y Z )
:1<.~11rj\SE6
( 7 Y X (4 V 'J 'I' ,L, IT: fJ P 0 N IY L K r l I M i2 F E D C d A)
! tj:?' ?i9OirlV) SECS
1 4 ~ LLi\1brl'h OF THE ii7ST LIsl' 26
5 4 53 58 51 SO 49 45 47 46 45 44 43 42 41 4C4 39 38 3 7 3 6 3 5 34 3 3 3d
31 363 29 28 27 26 2 5 2 4 23 22 21 28 19 1Y 1 7 16 15 1 4 13 12 1 1 18 9
7 6 ' 5 4 3 2 1 )
1. (4 17Q50t443 SECS
IIE\/Et?SE4
(1(;?$3 99 98 97 96 95 94 93 92 91 90 89 88 87 96 8 5 8 4 83 82 81 80 7 9 7
R '77 7 6 7 5 7 4 73 72 71 78 69 68 6 7 66 6 5 6 4 63 62 61 60 59 58 57 5 6 5 3
54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 3 7 36 35 34 33 32
31 33 2 9 28 27 26 2 5 2 4 2 3 22 21 20 19 18 17 16 15 1 4 13 12 11 1 @ 9 6;
7 6 5 4 3 2 1)
0.61 599999 SECS
r.;EVEr\rSES
< l @a 99 98 97 96 95 94 93 92 91 9@ 89 88 R 7 86 8 5 A 4 83 82 81 HP) 7 3 7
8 77 76 7 5 7 4 7 3 72 71 70 69 68 67 66 6 5 64 63 62 61 6 @ 53 58 57 56 5 5
54 53 5% 51 '563 49 48 47 46 45 44 43 42 41 40 39 36 37 36 3 3 34 3 3 3%
31 3fl 29 28 27 26 2 5 24 23 22 21 28 19 1 X 17 16 15 14 13 12 1 1 I @ 9 8
7 6 5 4 3 2 1 )
I?. 54999999 SECS
~ E V E I ~ S E ~
C1913 99 38 97 96 9 5 94 9 3 92 91 9fl 89 88 87 86 8 5 K 4 83 82 81 80 79 7
8 77 7 6 7 5 7 4 73 72 71 70 69 68 67 66 6 5 6 4 63 62 61 60 59 58 57 56 5 5
5 4 53 52 51 5@ 49 45 47 46 45 44 43 42 41 4@ 39 38 3 7 36 3 5 34 33 32
31 33 R 9 28 27 26 2 5 2 4 23 22 21 20 19 1F 17 16 15 14 13 12 1 1 1M 9 Y
7 6 5 4 3 2 1 )
!1* 534E10QQ8 SECS
1. Enea, Horace, MLISP, j Technical Report No. CS92, Computer Science
Department, St anford Uni versi t y, 1968.
2. McCarthy, J., Abrahams, P., Edwards, D. , Hart, T. , Levin, M. ,
JlISP 1. 5 Programmer's Manual, The Computation Center and Research
LabaraOory o f El ect roni cs, Massachusetts I ns t i t ut e of Technology,
MIT Press, 1965.
3. Quam, Lynn, , St anford Ar t i f i c i a l I nt el l i gence
Laboratory Operating Note 28.2, St anford Uni versi t y, 1968.
4. Weissman, Clark, LI$P 1. 5 Primer, Dickenson Publishing Company, Belmont,
Cal i f or ni a, 1967.

Das könnte Ihnen auch gefallen