This action might not be possible to undo. Are you sure you want to continue?
LISP 1.5 Programmer's Manual
The Computation Center and Research Laboratory of Eleotronics Massachusetts Institute of Technology
John McCarthy Paul W. Abrahams Daniel J. Edwards Timothy P. Hart
The M. I.T. Press
Massrchusetts Institute of Toohnology Cambridge, Massrchusetts
The research reported in this document was made possible in part by support extended the Massachusetts Institute of Technology.S. and in part by Contract DA-SIG-36-039-61-G14. Department of the Army Task 3-99-25-001-08. Army. Air Force (Office of Scientific Research) under Contract DA36-039-sc-78108. the U.S.S. jointly by the U. Navy (Office of Naval Research). additional support was received from the National Science Foundation (Grant G-16526) and the National Institutes of Health (Grant MH-04737-02). SECOND EDITION Elfteenth printing. 1985 ISBN 0 262 13011 4 (paperback) . Research Laboratory of Electronics. and the U.The Research Laboratory af Electronics is an interdepartmental laboratory in which faculty members and graduate students from numerous academic departments conduct research. Reproduction in whole or in part is permitted for any purpose of the United States Government.
David M. Russell and Daniel J . Bertram Raphael. Slagle. 1960. An e a r l i e r compiler was written by Robert Brayton.PREFACE The over-all design of the LISP Programming System is the work of John McCarthy and is based on his paper NRecursiveFunctions of Symbolic Expressions and Their Computation by Machinett which was published in Communications of the ACM. The print and read programs were written by John McCarthy. Daniel G . Edwards. J a m e s R. Edwards. Minsky. Additional programs and suggestions were contributed by the following mem b e r s of the Artificial Intelligence Group of the Research Laboratory of Electronics: Marvin L. David C . Levin. The interpreter was programmed by Stephen B. Bobrow. Luckham. Daniel J . The "LISP 1 Programmer's ManualsttMarch 1. April 1960. The garbage collector and arithmetic features Were written by Daniel J. Levin. and Paul W. Hart and Michael I. R. Abrahams. 1962 - . Klim Maling. The compiler and assembler were written by Timothy P . This manual was written by Michael I. and Nathaniel Rochester. was written by Phyllis A . August 17. Edwards. Fox. Park. Louis Hodes.
1 Symbolic Expressions 1 . 1 Variables 2 . THE PROGRAM FEATURE VI. RtTNNING THE LISP SYSTEM 6 . 3 Predicates and Truth in LISP IV. 3 E r r o r Diagnostics 6 . 6 Programming for the Interpreter In.2 . 1 Reading and Printing Numbers 4 . 5 Special Forms 2 . 2 Logical Connectives 3 . THE LISP INTERPRETER SYSTEM 2. THE LISP LANGUAGE 1. 2 Arithmetic Functions and Predicates 4 . 4 The cons Counter and errorset 6. 4 The LISP Meta-language 1. 3 List Notation 1 . 1 Functional Arguments 3 . 1 Preparing a Card Deck Tracing 6 . ARITHMETIC IN LISP 4.5 Syntactic Summary 1 . 2 Constants 2 . 2 Elementary Functions 1 . 3 Programming with Arithmetic 4 . 6 A Universal LISP Function 11. 3 Functions 2.4 Machine Language Functions 2 .TABLE OF CONTENTS I. 4 The Array Feature V. EXTENSION OF THE LISP LANGUAGE 3.
LIST STRUCTURES 7. 5 The Free-Storage List and the Garbage Collector THE WANG ALGORITHM VIII. A COMPLETE LISP PROGRAM FOR THE PROPOSITIONAL CALCULUS APPENDIX A Functions and Constants in the LISP System APPENDIX B APPENDIX C APPENDIX D APPENDIX E APPENDIX F The LISP Interpreter The LISP Assembly Program (LAP) The LISP Compiler OVERLORD - .The Monitor LISP Input and Output APPENDIX G Memory Allocation and the Garbage Collector APPENDIX H APPENDIX I Recursion and the Push-Down List LISP for SHARE Distribution INDEX TO FUNCTION DESCRIPTIONS GLOSSARY . 1 Representation of List Structure 7 . 2 Construction of List Structure 7 .CONTENTS VII.4 List Structure Operators 7 . 3 Property Lists 7.
This consists of recursive functions of S-expressions. The first way is in the nature of the data. This type of memory organization f r e e s the programmer from the necessity of allocating storage for the different sections of his program.1 Symbolic Expressions The most elementary type of S-expression is the atomic symbol. B. In the LISP programming system. It is therefore podsible to give a concise yet complete description of it. Examples A APPLE PART2 EXTRALONGSTRINGOFLETTERS A4B66XYZ2 These symbols a r e called atomic because they a r e taken a s a whole and a r e not capable of being split within LISP into individual characters. It has been used for symbolic calculations in differential and integral calculus. it will be called the meta language. All S-expressions a r e built out of atomic symbols and the punctuation marks . the first character must be a letter. These expressions will therefore be called M-expressions .I. THE LISP LANGUAGE The LISP language is designed primarily for symbolic data processing. and AB have no relation to each other except in so far a s they a r e three distinct atomic symbols. LISP is a formal mathematical language. Third. like machine language. and other fields of artificial intelligence. so that significant subexpressions can be readily isolated. all data a r e in the form of symbolic expressions usually referred to a s S-expressions. Such is the purpose of this first section of the manual. and unlike most other higher level languages. LISP can interpret and execute programs written in the form of Sexpressions. Thus. Thus A. LISP differs from most programming languages in three important ways. mathematical logic. it can be used to generate programs for further execution. Definition: An atomic symbol is a string of no more than thirty numerals and capital letters. electrical circuit theory. 1. S-expressions a r e of indefinite length and have a branching t r e e type of structure. Other sections will describe ways of using LISP to advantage and will explain extensions of the language which make it a convenient programming system. game playing. In the LISP language. Since the notation for the writing of recursive functions of S-expressions is itself outside the S-expression notation. The second important part of the LISP language is the source language itself which specifies in what way the S-expressions a r e to be processed. the bulk of available memory is used for storing S-expressions in the form of list structures.
. ((U V) . (B1 . a dot. c a r [ ( ( ~ l A2) B)]=(AI A2) car[^] is undefined .B]=(A . The next pair of functions do just the opposite of cons. an S-expression. Y)) ((U VI . . Examples car[(^ B)]=A car[(^ . The first function that we shall introduce is the function cons. we shall write function names in lower case letters. The function car has one argument. . From the two atomic symbols A1 and A2. since atomic symbols consist of only upper case letters. B) I The last example is an instance of composition of functions.( . an Sexpression. B ~ ) ) ] = A . . (X . As a separator o r punctuation mark we shall use the semicolon. Examples ATOM (A B) (A (B C)) ((A1 A2) B) . Notice that this definition is recursive. . Examples CO~S[A. . I t s value is the first part of i t s composite argument. . They produce the subexpressions of a given expression. It has two arguments and is in fact the function that is used to build S-expressions from smaller S* expressions. and . The basic operation for forming S-expressions is to combine two of them to produce a l a r g e r one.2 Elementary Functions We shall introduce some elementary functions of S-expressions. a of an atomic symbol is undefined. To distinguish the functions from the S-expressions themselves. one can form the S-expression (A1 A2). the arguments of functions will be grouped in square brackets rather than parentheses. and a right parenthesis. Definition: An S-expression is either an atomic symbol o r it is composed of these elements in the following order: a left parenthesis. (X (Y Z))) 1. Furthermore. It is possible to build any S-expression from its atomic components by compositions of the function cons.
B]]=A Given any S-expression. we shall use the same type of character strings that are used in forming atomic symbols..represent any two S-expressions. and false if its argument i s composite. . ( B)] i s undefined ~ e q [ ( ~ B).The function & has one argument. In LISP. B ~ ) ) ] J = B 1 car[cdr[(A . the following identities are true: car cons[^. It is undefined for non. B)]] i s undefined car[cons[A.^ J]=x cdr cons[^. A function whose value i s either true o r false i s called a predicate. Examples cdr[A] i s undefined carlcdr [(A . - . In LISP.^]]=^ The following identity is also true for any S-expression x such that x is composite (non. In choosing names for variables and functions.(A B)] is undefined . . Examples eq[A.atomic arguments . the values true and false are represented by the atomic symbols T and F.B]=F e q [ ~ . v)]=F atom[car [(u v)]]=T . Examples ~~~~~EXTRALONGSTRINGOFLETTERS]=T atom[(^ . it i s possible to produce any subexpression of it by a y suitable composition of c a r t s and c s s . cdr i s also undefined if its argument i s atomic. The predicate atom . The p r e d i c a t e s is a test for equality on atomic symbols.o true if its argument is an atomic symbol.A]=T ~~[A. vary iables a r e used to represent S-expressions. Its value is the second part of its composite argument. If 5 and .tively. except that we shall use lower case letters. respec. A LISP predicate i s therefore a function whose value i s either T o r F.atomic): The symbols x and -used in these identities a r e called variables. (B 1 .
. . NIL) . NIL))) (A)z(A NIL) ((A))=((A. the blank is now generally used. Examples car[(^ B c)]=A c d r [ ( ~3 c)]=(B C) I cons[^. LISP has an alternative form of S-expression called the list notation. . This is done by forming function names that begin with c. (D NIL)) . Historically. (C NIL))) ((A B ) C)=((A (B . . . mn) can be defined in t e r m s of dot notation.). . (B ((C . The dot notation and the list notation may be used in the same $*expression. C))*(A ((B C ) . however. . Examplee (A B c)=(A (B . These can always be determined by translating into dot notation. However. It is usually more convenient to be able to write lists of expressions of indefinite length. . end with r. The atomic symbol NIL serves a s a terminator for lists. (mn NIL). Examples c a d r [ ( ~ ~ ) ] s c a r [ c d r l ( A C)I=B B B caddr[(A B C )I=c cadadr[(A (B C) D)]=c . . qnd have several a ' s and dl s between them. B.=s. NIL)) . such a s (A B C D E). C) is identical to (A B C).. . It Is important to b e c ~ m e familiar with the results of elementary functions on S-expressi~ss written in list notation. Lists may have sublists.1. The two a r e entirely equivalent in LISP. NIL)) . (B c)]=(A B C) car[((^ B) c)]*(A B ) c~~[(A)]=NIL c a r [ c d r [ ( ~ C)]]=B B It is convenient to abbreviate multiple car's and. .. ))). . the separator for elements of lists was the comma (. (C NIL)) (A B (C D))=(A . The list ( m l mZ . . (A. The null list ( ) is identical to NIL. . NIL) (A (B . Any S-expression can be expressed in terms of the dot notation. . . It is identical to ( m l (m2 ( .3 List Notation The S-expre~sionsthat have been used heretofore have been written in dot notation.
then if p2 is true the value of e 2 is the value of the entire expression.The last a o r d in the name actually signifies the first operation in order to be performed. since it is nearest to the argument. These rules allow one to write function definitions such a s third[x]=car[cdr[cdr[x]]]. Function names and variable names a r e like atortlfc symbols except that they use lower case letters. For example. 1 . The arguments of a function a r e bound by square brackets and separated from each other by semicolons. T-x] ~ The atomic symbol T represents truth. Compositions of functions may be written by using nested s e t s of brackets. 1. Example [ e q [ c a r [ x ] . and each ei is any expression. The pi a r e searched from left to right until the first true one is found. then the value of the entire expression is undefined. third is actually the same function a s caddr. If none of the pi a r e true. ~ ] e o n s [. Then the corresponding ei is selected. We have also discussed the following features of the metalanguage. This function selects the third item on a list. then the value of e l is the value of the entire expression. The class of functions that can be formed in this way is quite limited and hot Very interesting. 4 The LISP Meta-language We have introduced a type of data called S-expressions. If p l is false. A much larger class of functions can be defined by means of the conditional expression. but leaving x unchanged if of it is not A. 3. car car . A conditional expression has the following form: where each pi is an expression whose value may be truth o r falsity. ta composition of functions o r may it self be another conditional expression. The meaning of a conditional expression is: if p l is true. and five elementary functions of S-expressions. Each pi o r ei can itselk be either an 6-expression. 2.cdr[x]]. a device for providing branches in function definitions. a function. The value of this expression is obtained if one replaces of x by B if it happens to be A.
o r loop until the program is halted artificially. Otherwise the function ff is to be applied to car of x. C )]]I f f [ ( ( ~ B) = ff[car[((A . and so we have = [T-ff [car [((A . then the first branch which is x l1 will be selected. B)]]] The conditional expression is useful for defining numerical computations. B)]-(A . This expression can be read: If x is an atomic symbol. Example ff[x]=[atom[x]-x. a s well a s computations with S-expressions. one will eventually produce an atomic symbol. T-ff[car[x]]] This example defines the function ff which selects the first atomic symbol of any given expression. but infinitely recursive for certain other arguments. B). If x is atomic. T-n-[n-l]! 3 This recursive definition does not terminate for negative arguments. B) . it will either use up all of the available memory. The definition of ff is recursive in that ff is actually deefinedin t e r m s of itself. First. B) . If one keeps taking cay of any S-expression. c)]] = f f [ ( ~ B)] . B) . c)]. c)]]] but ((A . Otherwise. C)]=[atom[((A . since T is always true. the second branch nff[car[x]]n will be selected. . The absolute value of a number can be defined by The factorial of a nonhnegative integer can be defined by n! =[n=0-1. B)]] = ff[A] = [atom[A]-A. We shall now work out the evaluation of ff[((A . the definition of ff must be used recursively.The main application of conditional expressions is in defining functions recursively. Substituting (A for x gives = [atom[(A . then x itself is the answer. c)]-((A . B)]]] = ff[car[(A . C ) is not atomic. B) . B) . B) . T-ff [car [A 111 . A function that . Tdff[car[(A = [T-ff[car[(~ . B) . B) . we substitute the arguments in place of the variable x in the definition and obtain . When such a function is interpreted in the LISP programming system. C). At this point. Some recursive functions may be well defined for certain arguments only. therefore the process is always well defined. T-ff[car[((A .
~ [ L ~ . Princeton.4]=7.41 is 13 o r 19. y t x ] is a function of two variables. The Calculi of Lambda-Conversion (Princeton University P r e s s .y2+x1[3. 1 9 4 r . the value of the function must be undefined. . . and to apply it to f o r m s such a s JI 2 Because we shall later compute with expressions that stand for functions. The notation that we shall use 1 is the lambda notation of Alonzo Church. Unless n has been given a value before trying to compute with this function. F o r example. ~ ~ We shall sometimes use expressions in which a variable is not bound by a lambda. respectively. Proceedings of the Western Joint Computer Conference. May 1961 (published by the Institute of Radio Engineers). The variables in a lambda expression a r e dummy o r bound variables because s y s tematically changing them does not a l t e r the meaning of the expression.4] and to be able to determine the value of this expres2 sion..is defined only for certain arguments is called a partial function. ~ I 2 = 3 +4=13. €1 u t s r e p r e s e n t s the function of n variables obtained by substituting the n arguments in o r d e r for the variables x l . T h i s is called a f r e e variable. sum[3.. . 2 It is not at all c l e a r whether the value of y +x[3. we need a notation that e x p r e s s e s the distinction between functions and f o r m s . x J Y ~ + ~ I [ ~ . be an expression that stands for a function of two integer variables. ~ ] ..xn.xn. A form can be converted to a function by specifying the correspondence between the variables in the f o r m and the arguments of the desired function. The expression y t x does not meet this requirement. and )i[[x. The Euclidean algorithm for finding the greatest common divisor of two positive integers can be defined by using conditional expressions a s follows: rem[u. A. . .4]=4 +3=19. If E is a f o r m in the variables x l.. ~ tx]. An expression such a s 2 y t x will be called a f o r m r a t h e r than a function. New J e r s e y .y). the function ~ [ [ x . Thus X[[u. F o r example. then the expression h[[x l.xn].vi is the remainder when is divided by 2 A detailed discussion of the theory of functions defined recursively by conditional expressions is found in A B a s i s for a Mathematical Theory of Computation " by J . F o r example. Church. .vk 2 2 v t u ] means the s a m e thing a s A [ [ X . It is usual for most mathematicians-exclusive of those devoted to logic-to use the word function imprecisely. . It Let should make sense to write f[3. It may be regarded a s a parameter. 2 2 1. McCarthy. in the function of two variables )i[[x.y~xntyn]the variable n is not bound.
The rule In Backus notation the symbols I 1 : : = l 1 . I The Data Language CLETTER>::~AIB <number>::=0I112 (9 c atomic-symbol >::=<LETTER . l1 > " . The Syntax and Semantics of the Proposed International Algebraic Language of the Zurich ACM-Gamm Conference. I1<l1. ~ ] . . . June 1959. If E is an expression. we can write ff=h[[xh [atorn[x]-x. The vertical bar means o r " . The definition is given in Backus notation2 with the addition of three dots(. T-ff [car [x]]j) The equality sigq in these identities is actually not part of the LISP meta-language and is only a orutch until we develop the correct notation. together with semantic comments. .<atom pqrt > <atom part >::=<empty > I <LETTER ><atom part > <number ><atom part > IcI.. o r it is a left parenthesis followed by an S-expression followed by a dot followed by an S-expression followed by a right parenthesis. The function 3 can now be written without an equal sign: In this expression. and It fl a r e used. is a bound variable. <S-expression >::=<atomic symbol > (<S-expression > <S-expression>) means that an $-expression is either an atomic symbol. The right side of the last equation cannot s e r v e as an expression for the function &because there is nothing to indicate that the occurrence of ff inside it stands for the function that is being defined... I Z I Atomic symbols a r e the smallest entities in LISP. ICIP P a r i s . and f is a bound function name.. Not only must the variables be bound. Backus. In o r d e r to be able to write expressions that bear their own name. W. This election is f o r completeness and may be skipped upon f i r s t reading.5 Syntactic $ummaryl All parts of the LISP language have now been explained. That which follows is a complete gyntactic definition of the LISP language. The function ff was previously defined by the identity Using the lambda notation. since it is used inside an expression to stand f o r the entire expression.) to avoid naming unneccessary syntactic types. . J. f 1. I . and o is i t s name. 2. Their decomposition into chara c t e r s has no significance. we introduce the label notatioe. we write l a b e l [ a . and the angular brackets always enclose elements of the syntax that is being defined. 1.The lambda notation alone is inadequate f o r naming recursive functions. but the name of the function must be bound.
they mean that any number of the given type of symbol may occur.<form >] label[< identifier >. The last part of this rule gives the format of the conditional expression. it must be given a name by using a label. although the list notation is often more convenient. A function may be defined by using the lambda notation and establishing a correspondence between the arguments and the variables used in a form. .. ( ) is a valid S-expression. <S-expression >) . I The names of functions and variables a r e fornied in the same manner a s atomic symbols but with lower -case letters. ) The dot notation is the fundamental notation of S-expressions. According to this rule. In this case i t s meaning must be previously understood. including none at all.<variable >] A function can be simply a name.< S-expression >::=<atomic symbol > ( (<S-expression > <S-expression >) (<S-expression > . The third part of this rule states that we may write a function followed by a list of arguments separated by semicolons and enclosed in square brackets. The Meta-Language <letter>::=alb(cl. Any Sdexpression can be written in dot notation. . I When three dots a r e used in this manner. . <function >] <var list >:: =[<variable >. . then the value of the f o r m is the S-expression that is bound to that variable at the time when we evaluate the form. The expressions for the arguments a r e themselves forms. A f o r m is an expression that can be evaluated. <function >::=<identifier > ( k[<var list >. Then the form after the arrow is evaluated and give$ the value of the entire expression. A f o r m that is merely a constant has that constant a s i t s value. This is evaluated by evaluating the f o r m s in the propositional position in order until one is found whose value is T . . If a form is a variable. ( z <identifier >::=<letter ><id part > <id part >::=<empty > <letter ><id part > I <number ><id part > . If the function is recursive. (It is equivalent to NIL. this indicates that cornpasitions of functions a r e permitted. I . .
2 .atgn] is translated into (fn* argl* . . . Since we have been writing functions a s M-expressions.args]. 3. the argument of the function evalquote must be an S-expression..[atom[x]-x. 2. it is translated by changing is translated all of the letters to upper case. 3 . Thus X is translated into (QUOTE X). pn-en] is translated into (COND "fn" . then the expression k[[x . . argn*) 4. it computes the value of the function applied to the arguments. The conditional expression [Pl-el. The solution is to quote it. is X. In particular. [XI] T-ff [car [x]]] T-ff[car label[ff ..h[[x].. F o r m s a r e translated a s follows: 1. like a function name..xn]. Thus the translation of v a r l is VAR1. it is necessary to translate them into S-expressions. . A variable. the translation of X must be something else to avoid Since the translation of ambiguity. . ) We a r e now in a position to define the universal LISP function evalquote[fn. .. [XI]]]] S-expressions X CAR (CAR X ) (QUOTE T) ( F F (CAR X)) (COND ((ATOM X) X) ((QUOTE T) ( F F (CAR X)))) (LABEL F F (LAMBDA (X) (COND ((ATOM X) X) ((QUOTE T) ( F F (CAR X ) ) ) ))) Some of them Some useful functions for handling S-expressions a r e given below. Examples M-expressions X car c a r [x] T ff [car [atom[x]-x. where E* is the translation of c. is translated by using uppercase letters.6 A Universal LISP Function An interpreter o r universal function is one that can compute the value of any given function applied to i t s arguments when given a description of that function. Thus to CAR. The following rules define a method of translating functions written in the metalanguage into S-expressions 1. XN) e*). * * . The form fn[argl.. If the function begins with label. When evalquote is given a function and a list of arguments for that function.1. .. 1 is translated into (LAMBDA (X1 . LISP functions have S-expressions a s arguments. The obvious translation of letting a constant translate into itself will not work. the interpreter will r e c u r infinitely also. if the function that is being interpreted has infinite recursion. (Of course. making i t an atomic symbol. If the function is represented by i t s name. If the function uses the lambda notation. € I is (LABEL a* e*). then the translation of label[= .
B ) .~ . We have memberlx. It is true if and only if its argument is NIL. 1 .atom[z] z[ z z. The following functions a r e useful when S-expressions a r e regarded a s lists. and is false if they a r e different. A)) . we have S U ~ S ~ [ . append[cdr [x]. y] = [ n ~ l l [ x ] . This is a predicate that is true if i t s two arguments a r e identical S-expressions. T-F].T [x. - (LABEL EQUAL (LAMBDA (X Y) (COND ((ATOM X ) (COND ((ATOM Y) (EQ X Y)) ((QUOTE T ) (QUOTE F ) ) ) ) ((EQUAL (CAR X) (CAR Y)) (EQUAL (CDR X) (CDR Y))) ((QUOTET)(QUOTEF)) )I) sub st[^. subst[x. T-F] This can be translated into the following S-expression: .-. car[z]]. ) The definition of inside a conditional expression.y. A). I]] member[^.y] . y.(C D E ) ] = (A B C D E ) 2. y]=[atom[x] atom[^] -eq[x.^] This predicate is true if the S-expression x occurs among the elements of the list y. cdr [y]]. T-cons[car [x]. It is defined by s ~ b s t [ x . equal[car [x]. equal[x. z] This function gives the result of substituting the S-expression x for all occurrences of the atomic symbol y in the S-expression z. y] append[x. cdr [y I]] . (X . c a r [Y]]-equal[cdr [x].^. c a r [y ]I--T. T-member [x.((A (X null[x] This predicate is useful for deciding when a list is exhausted. y] = [null[y ]--F.- cons[subst . egual is an example of a conditional expression equal[x.a r e needed a s auxiliary functions for evalquote equal[x. c)] = ((A . cdr[z]]]] As an example.B.~]. (The elementary predicate eq is defined only for - atomic arguments. C) .]x.= ] e q ~ a l [ ~ . ~ . append[x. y An example is append[(A B).
argn). pairlis[cdr[x]. and appends this to the list a. . (CAR x)) 5. y] = [at0rn[~]-sub2[a..~].eq[caar[a]. T-cons[cons[car[x]. and let fn be i t s translation. . Y)) assoc[x. (QUOTE M)).(U V w). (B = (B . V ) (C . then assoc will produce the f i r s t pair whose f i r s t t e r m is x. where the u1 s a r e atomic..((D X) ( E ( ( A .This function gives the list of pairs of corresponding elements of the l i s t s x and y. We have An example is a s s o c [ ~ . and y is any S-expression. Thus it is a table searching function. z] = [null[a]+z. cdr [y]. z]-cdar[a]. We have pairlis [x. cdr [Y]]]] An example is sublis[((X SHAKESPEARE) (Y . Let f be a function written a s an M-expression.~sub%[cdr[a]. . . (CAR X)). car[y]]. . a]]] An example is pairlis[(A B C). . . ) Let f be a function of n arguments and let args=(argl . sublis[a. (& is an S-expression. We have sub2[a. a list of the n S-expressions being used a s arguments. which is like a table with two columns. U) (B 4.(X WROTE Y)] = (SHAKESPEARE WROTE (THE TEMPEST)) The universal function evalquote that is about to be defined obeys the following identity. we f i r s t define an auxiliary function.(C .z]] and sublis[a. Y))] = . . What sublis does. (CDR x)))] . Then . y. a] = [null[x]--a. In order to define sublis. The resultant list of pairs.y] Here a is assumed to be an association list of the form ((ul v l ) (un v.)). is called an association list. (C . T-cons[sublis[a. and to substitute the corresponding v1 s f r o m the pair list. (THE TEMPEST))). X ) (E . car[^]]. ( ( A (MN)). a] If a is an association list such a s the one formed by pairlis in the above example. is to treat the u1 s a s variables when they occur in y. sublisla. . W ) ( D .
CONS] -. a].x.(C Dl]= (A C D) evalquote is defined by using two main functions. eq[car[fn]. a ] = [eval[caar [c].a] = [atom[e] atom[car[e]] - - c addr [f n]].x. a]. ~ -. ~ -.evcon[cdr [c]. a]].eval[caddr [fn]. Example fi fn: argl: arg2: args: ~[[x. ~] e q [ f n . e q [ f n .a] = [null[m] NIL.apply[car [el. T -.a]]] . x. evcon[c.a]] and evlis[m.evlis[cdr [m]. apply[car [el.cons[car[x]. COND] evcon[cdr [el.a]].- .x. eq[car[e].a]. while eval handles forms. a]] - - pairlis and assoc have been previously defined. Each of these functions also has another argument that is used a s an association list for storing the values of bound variables and f unction names.cons[car[x]. eq[fn. called eval and apply.a]]. a] = [atom[fn] - [ e q [ f n . a]]] cdr[assoc[e. eq[car [fn]. apply handles a function and i t s arguments. T - - - eval[e. ~ ~ caar[x].eval[cadar [c]. pairlis[cadr[fn]. T -.y]] (LAMBDA (X Y) (CONS (CAR X) Y)) (A B) (C D) ((A B ) (C D)) evalquote[(LAMBDA (X Y) (CONS (CAR X ) Y)).y]][(A B).~].cons[car[x].a]].if either side of the equation is defined at all. LAMBDA] -. evlis [cdr [el. T cons [eval[car [m]. ((A B ) (C D))] = ~[[x.atom[car[x]]. evlis[cdr [el. cons [cons[cadr [fn]. a] -. T - [eq[car QUOTE] cadr [el. where apply [fn.~ ] ~ cdar[x]. a].y]. a].a]. cadr[x]]. LABEL] apply [caddr [fn]. EQ] eq[car[x]. - apply[eval[fn. ~ ~ ~ ] eq[fn. cadr[x]].
then it is a conditional expression. The a r guments a r e then evaluated. although it may not always be meaningful. it is worth noting the following points. but T. The effects of these functions in unusual cases will be understood after reading the chapter on list structures in the computer. the form is QUOTE. o r atom. and i t s value is looked up on the association list. In all other cases. cons. The LISP Programming System has many added features that have not been described thus far. 2. One is that it is an elementary function: car. - - . This is unworkable in a practical sense. then the arguments a r e paired with the bound variables. and cdr were said to be undefined for atomic arguments. to evaluate. cdr. they always have a value. These a r e introduced a s psuedo-atomic symbols. then there a r e two possibilities. all functions other than the five basic ones need to be defined each time they a r e to be used. the basic predicate eq always has a value. 4 . The LISP programming system has a larger stock of built-in functions known to the interpreter. and evcon evaluates the propositional t e r m s in order. Appendix B contains the computer implemented version of these functions and should be used to decide questions about how things really work. The first argument for apply is a function. The first argument of is a form. then the function name and definition a r e added to the a s sociation list. In each case. and the form is given to 1 If it begins with LABEL. The basic functions car. and provision for adding a s many more a s the programmer c a r e s to define. then it is a constant. then i t s meaning has to be looked up in the association list. In the pure theory of LISP. Except for very unusual cases. In the system. and the inside function is evaluated by apply. eq. There is provision in LISP for computing with fixed and floating point numbers. one never writes (QUOTE T ) o r (QUOTE F). 3 . then it must be a variable. and the value is cadr of the form If =of itself. the appropriate function is applied to the argument(s). If it is not one of these. At this point. If it is atomic. and choses the form following the first true predicate. and F respectively. These will be treated hereafter. 1.We shall explain a number of points about these definitions. If it begins with LAMBDA. If it is an atomic symbol. The reader is warned that the definitions of apply and ~l given above a r e pedagogical devices and a r e not the same functions a s those built into the LISP programming system. If car of the form is CGND. Similarly. the form must be a function followed by i t s arguments. and the function is given to apply.
y]-union [cdr [x]. THE LISP INTERPRETER SYSTEM The following example is a LISP program that defines three functions union. The functions a r e defined a s follows. and member. The first list o r atomic symbol of each doublet is interpreted a s a function.car[x]]-T. Its value is a list of the functions defined.member[car[x].Tmember [a. 1 . The first function is the pseudo-function define.x] = [null[x]-~.5 programs. A program for execution in LISP consists of a sequence of doublets. and then applies these functions to some test cases.11. The value of the third function is (Y Z U V W X). Following a r e some elementary rules for writing LISP 1. An inspection of the way in which the recursion is carried out will show why the I1elementsNof the Itset" appear in just this order.union[c d r [x]. member[a. in this case (MEMBER UNION INTERSECTION). define causes these functions to be defined and available within the system.~]. The functions union and intersection a r e to be applied to "sets.cdr [x]]] union[^.e~[a. A pseudo-function is a function that is executed for i t s effect on the system in core memory. The value of the second function is (A1 A3). a s well a s for i t s value.^] = [null[x]-. . we use the pseudo-function define. T-cons [c a r [x]. The second is a list ." each set being represented by a list of atomic symbols. The program looks like this : DEFINE (( (MEMBER (LAMBDA (A X) (COND ((NULL X) F) ( (EQ A (CAR X) ) T) ( T (MEMBER A (CDR X))) ))) (UNION (LAMBDA (X Y) (COND ((NULL X) Y) ((MEMBER (CAR X) Y) (UNION (CDR X) Y)) ( T (CONS (CAR X) (UNION (CDR X) Y))) 1)) (INTERSECTION (LAMBDA (X Y) (COND ((NULL X) NIL) ( (MEMBER (CAR X) Y) (CONS (CAR X) (INTERSECTION (CDR X) Y))) ( T (INTERSECTION (CDR X) Y)) ))) 1) INTERSECTION ((A1 A2 A3) (A1 A3 A5)) UNION ((X Y Z) (U V W X)) This program contains three distinct functions for the LISP interpreter. and both union and intersection make use of member.y.~]]] To define these functions. intersection. Note that they a r e all recursive.
including indentation. 2 . An atomic symbol may be either a variable o r an actual argument. A form of the type (A B C D) is an abbreviation for (A . the situation can be much more complicated. . is a valid S-expression. 4. Use T. i t is necess a r y to substitute the actual numbers for the variables. 6 . (G . 1 Variables A variable is a symbol that is used to represent an argument of a function. (B (C D))). 3. 2. B) 8. Atomic symbols should begin with alphabetical characters to distinguish them from numbers. (E . . Everything in this section can be derived from the rule for . The order in which functions a r e introduced is not significant. ( F . F. Any other mixing of commas (spaces) and dots on the same level is an e r r o r .of arguments for the function. To further complicate the situation. .5. The format of this program. There is no particular card format for writing LISP. ((A ((A It could also be written . They a r e evaluated by evalquote. A selection of basic functions is provided with the LISP system. where a = 341 and b = 216. and the value isprinted. and (QUOTE NIL). 9. For example. Any number of blanks before or after the dot will be ignored. Do not use the forms (QUOTE T). In order to arrive a t this result. 5. a part of an argument may be a variable when a function inside another function is evaluated. Columns 1-72 of anynumber of c a r d s may be used. Any number of blanks and/or commas can occur a t any point in a program except in the middle of an atomic symbol. was chosen merely for ease of reading. Thus one might write "a + b. (X . (A B C) . Lest the prospective LISP user be discouraged a t this point. and NIL instead.11 In this situation no confusion can result and all will agree that the answer is 557. An understanding of the formalism in use is necessary to do any effective LISP programming. Other functions may be iytroduced by the programmer. 7. and i t is therefore obvious that they merely represent the actual arguments. Dotted pairs may occur a s elements of a list. and lists may occur a s elements of dotted pairs. (QUOTE F). A comma is the equivalent of a blank. In LISP. The intuitive approach is no longer adequate. NIL))) or . ((C . g . This section is intended to reinforce the discussion of Section I. Card boundaries a r e ignored. NIL)))) . B) X (C E F G)) . it should be pointed out that nothing new is going to be introduced here. Any function may make use of any other function. e . . One reason why there is no ambiguity in this case is that llalland "bl1 a r e not acceptable inputs for an adding machine. and then add the two number (on an adding machine for instance). Dot notation may be used in LISP 1.
variables may be encountered. thus making i t possible to s e t constants. then the symbol is a constant and the next item on the list is the value. The part of the interpreter that does this is called eval.will bind the variables and give the function and a-list to eval. c . B))]. since the student who is learning calculus is taught to represent constants by a. This is not a very workable concept. z. Suppose the interpreter is given the following doublet: fn: (LAMBDA (X Y) (CONS X Y)) args: (A B) evalquote will give these arguments to apply.((X . The part of the interpreter that binds variables is called apply. B))] eval will evaluate the variables and give i t to cons. It seems more reasonable to say that one variable is more nearly constant than another if it is bound at a higher level and changes value l e s s frequently. When the p-list contains the indicator APVAL. When a variable always has a certain value regardless of the current a-list. The following example will illustrate this discussion. the last o r most recent value is used. 2 Constants . namely.NIL] (X A apply . A) (Y . eval searches p -lists before a-lists when evaluating variables. If a variable has been bound several times..(A 2 .. . . In LISP. Constants can be made by the programmer. This is accomplished by means of the property list (p-list) of the variable symbol. y. and variables by x. for (A B C D). During the evaluation of the function. To make the variable X always stand t . ) ~ P ~ ~ Y [ ( L A M B DY) (CONS X Y)). (Look a t the universal function of Section I. When apply encounters a function beginning with LAMBDA. cons[^. B) The actual interpreter skips one step required by the universal function. o r alternatively everything in this section can be inferred from the universal function evalquote of Section I. the list of variables is paired with the list of arguments and added to the front of the a-list . Every atomic symbol has a p-list. - It is sometimes assumed that a constant stands for itself a s opposed to a variable which stands for something else. a variable remains bound within the scope of the LAMBDA that binds i t . Property lists a r e discussed in Section VII. A) (Y . (A B). . b. it will be 1 called a constant. The formalism for variables in LISP is the Church lambda notation.^] = (A . . a p p l y [ ~ O ~ ~B). They a r e evaluated by looking them up on the a-list.translating M-expressions into S-expressions. 1 . e v a l [ ( ~ ~ N ~ ((X X Y). use the pseudo-function ~ .
QUOTE is a special form that prevents i t s argument from being evaluated. Such a function w i l l have the indicator SUBR on i t s property list followed by a pointer that allows the interpreter to link with the subroutine. just a s a variable is bound to i t s value. 5 Special Forms Normally. it w i l l evaluate X and Y. NIL. T. 2 . The subroutine is coded into the LISP system. 2 . The function is first defined by an S-expression. On the contrary. the situation is similar to that in which a symbol stands for an argument. and then compiled by the LISP compiler. 3 . has a very special way of . F.An interesting type of constant is one that stands for itself. Thus i f = But if eval is given (QUOTE X). for example. COND. X should not be evaluated. 2. itself. which pairs the n&me with the function definition on the a-list. When a function is recursive. Its arguments a r e not evaluated before the special form sees them. NIL is an example of this. 3 Functions When a symbol stands for a function. is not due t o any weakness of the system. i t indicates a richness of the system which we do not know how to exploit very well. 2 . and then cons them. and not variables that a r e modified by the program. A special form differs from a function in two ways. The pseudo-function define used a t the beginning of this section accomplishes this. i t searches the p-list of the atomic symbol before searching the current a-list. LABEL is seldom used. it must be given a name. The name is then bound to the function definition. LAP. It is usually more convenient to attach the name to the definition in a uniform manner. The fact that most functions a r e constants defined by the programmer. There a r e three ways in which a subroutine can be present in the system. Compiled functions run from 10 to 100 times a s fast a s they do when they a r e interpreted. In actual practice. Thus a define will override a LABEL. This is done by means of the form LABEL. 4 Machine Language Functions Some functions instead of being defined by S-expressions a r e coded a s closed machine language subroutines.the symbolEXPR followed by the function definition. and other constants cannot be used a s variables. 1 . It can be evaluated repeatedly and will still be NIL. eval evaluates the arguments of a function before applying the function l is given (CONS X Y). This is done by putting on the property list of the name. The function is hand-coded by the u s e r in the assembly type language. When apply interprets a function represented by an atomic symbol.
He expected (CAR (QUOTE (A B))) to evaluate to A. B))) (CDR (QUOTE (C . Example 2 fn: CONS args: (A (B . This is correct but car unnecessary. 6 Programming for the Interpreter The purpose of this section is to help the programmer avoid certain common e r r o r s . respectively. . ------expects It does not expect a list of expressions that will evaluate to the arguments. Example 1 fn: CAR args: ((A B)) The value is A.evaluating i t s arguments by using evcon. 2 . The one arguis (A B).(^ c)]= (A . (B The print program will write this a s (A B Example 3 - fn: CONS args: ((CAR (QUOTE (A . C)). args: ((CONS (CAR (QUOTE (A The value of both of these is (A . The value is cons[^. D)) . ment for One could write (LAMBDA (X) (CAR X)) instead of just CAR. The extra pair of parentheses is necessary. B))) (CDR (QUOTE (C . The second one uses quoted arguments and gets them evaluated by eval with a null a-list. . and expected (A D) a s the value of cons. Special forrrls have indicators on their property lists called FEXPR and FSUBR for LISP -defined forms and machine language coded forms. fn: (LAMBDA (X Y) (CONS (CAR X) (CDR Y))) args: ((A fn: EVAL - . The second way which special forms differ from functions is that they may have an indefinite number of arguments. The first one makes the car and cdr part of a function specified by a LAMBDA. D)))) The value of this computation will be ((CAR (QUOTE (A B))) (CDR (QUOTE (C . . . . Tworcorrect ways of writing this function a r e listed -below. D) . D)))) NIL) .a list of arguments. C)) . The interpreter ---. B) (C . This is not what the programmer expected. . Note that the interpreter expects a list of arguments. C). D)))).
A universal function (written . it is possible to have functions a s arguments of other functions.4]= 1 2 and In LISP. 4. It is a function only in the trivial sense that its value happens to be its argument. The basis of the LISP Programming System is the interpreter. print is a function of one argument. Its effect is to print i t s argument on the output tape (or on-line). the command to print an S-expression on the output tape is called print. Commands to effect an action such a s the operation of input-output. Syntactically. A LISP program in fact consists of pairs of arguments for evalquote which a r e interpreted in sequence. For example. Thus operate[+. In some cases the value is trivial and may be ignored.. A very important function with a functional argument is maplist. For example.4]=7 operate[x. o r evalquote and its components. 3. Section I1 introduced the LISP Programming System. In this section we shall introduce a number of extensions of elementary LISP. in arithmetic one could define a function operate [op. In all cases. where op is a functional argument that specifies which arithmetic operation is to be performed on a and b . 2 . functional arguments a r e extremely useful.1 Functional Arguments Mathematically. w i l l be called pseudo-functions . or the defining functions define and cset discussed in Chapter 11. The first includes propositional connectives and functions with functions a s arguments. and they a r e also of a mathematical nature. 3 . It is characteristic of the LISP system that all functions including psuedo-functions must have values.3. additions to the LISP Programming System a r e made to conform to the functional syntax of LISP even though they a r e not functions.3. This Chapter i s concerned with several extensions of the LISP language that a r e in the system.a. and will be evaluated in the usual manner.IS an M-expression) for interpreting the application of any function written a s an S-expression to its arguments. the second is peculiar to the LISP Programming System on the IBM 7090 computer. A functional notation called M-expressions.111. Its M-expression definition is . The elements of this formal system a r e the following. A set of symbols called S-expressions.b]. EXTENSION OF THE LISP LANGUAGE Section I of this manual presented a purely formal mathematical system that we shall call pure LISP. A formal mapping of M-expressions into S-expressions. 1 . These extensions of elementary LISP a r e of two sorts. with the inside of the composition being evaluated f i r s t . It may be used in composition with other functions. thus making it an identity function.
g icates of an indefinite number of arguments. a function translated into an S-expression. X) ((C D) X)) Using maplist. It is bound to the variable fn and is then used whenever is mentioned a s a function. of course. they can be defined by using conditional expressions: & and or a r e predIn the System. then it is translated into (FUNCTION fn*). not is a predicate of one argument.maplist[x. 5 because a function appears where a form is expected.~[[j]. change[a]=maplist[a. An explanation of how the interpreter processes the atomic symbol FUNCTION is given in the Appendix B. change[(^ B (C D))]=((A . However. fn .fn]=[null[x]-NIL. and therefore a r e special forms. provided that there a r e no f r e e variables present. This can be corrected by modifying the rule defining an argument s o a s to include functional arguments: < argument > :: = <form > 1 c function > We also need a special rule to translate functional arguments into S-expression. In . Example (CHANGE (LAMBDA (A) (MAPLIST A (FUNCTION (LAMBDA (J) (CONS (CAR J) (QUOTE X))) ))) An examination of evalquote shows that QUOTE will work instead of FUNCTION.maplis t [cdr [x]. in LISP. X) (B . . The S-expression for maplist itself is a s follows: fn (MAPLIST (LAMBDA (X FN) (COND ((NULL X) NIL) (T (CONS (FN X) (MAPLIST (CDR X) FN))) ))) Now suppose we wish to define a function that takes a list and changes it by cons-ing an X onto every item of the list s o that. The functional argument is.2 If Logical Connectives The logical or Boolian connectives a r e usually considered a s primitive operators. 3.fn]]] An examination of the universal function evalquote will show that the interpreter can handle maplist and other functions written in this manner without any further addition. we define change by . for example. ~ ] ] ] This is not a valid M-expression a s defined syntactically in section 1 . However.is a function used a s an argument. T-cons [fn[x].cons[car [ j ] .
The symbols T and F for constant predicates will work because: The forms (QUOTE *T*) and (QUOTE NIL) will also work because *T* and NIL both have APVAL. Note that . of course. - 3 . The definitions of these predicated given above show that the value may be defined even i f all of the arguments a r e not.writing M-expressions i t is often convenient to use infix notation and write expressions such a s a V b V c for or[a. one must. The atomic symbols T and F have APVAL1s whose values a r e *T* and NIL.c]. The programmer may either accept this rule blindly o r understand the following Humpty-Dumpty semantics.'s that point to themselves. it was stated that in the system one must always write T instead.b. In S-expressions. r e spectively. These two atomic symbols a r e *T* and NIL. @ evaluates i t s arguments from left to right. then the value of the o is true and no further arguments a r e evaluated. It is these symbols rather than T and F that a r e the actual value of all predicates in the system. If the arguments a r e all evalr uated and found to be false. The order in which the arguments of and and o a r e given may be of some significance r in the case in which some of the arguments may not be well defined. 3 Predicates and Truth in LISP Although the rule for translating M-expressions into S-expressions states that T is (QUOTE T). or evaluates i t s arguments from left to right. If one of them is true. is false and no further arguments a r e evaluated. In the LISP programming system there a r e two atomic symbols that represent truth and falsity respectively. If one of them is found that is false. one must write F rather than (QUOTE F ) . then the value is true. If the arguthen the value of the ments a r e all evaluated and found to be true. Thus *T* and NIL a r e also acceptable because But QUOTE QUOTE F).NIL]= F which is wrong and this is why (QUOTE F) will not work. use prefix notation and write (OR A B C ) . Similarly. then the value is false. This is mainly a coding convenience.
1. The predicate eq has the following behavior. If i t s arguments a r e both the same atomic symbol. - - . One consequence of this is that the predicates null and not a r e identical. 3 .which is wrong but will work for a different reason that will be explained in the paragraph after next. There is no formal distinction between a function and a predicate in LISP. or a s an argument of a logical predicate. i t s value is *T*. This is true of all predicates in the System. 4. One may use a form that is not a predicate in a location in which a predicate is called for. such a s in the p position of a conditional expression. but a r e not atomic. any S-expression that is not NIL will be regarded a s truth in such a case. It is never undefined even if i t s arguments a r e bad. A predicate can be defined a s a function whose value is either *T* or NIL. 2. Semantically. The value of eq is always *T* o r NIL. If i t s arguments a r e both the same. If i t s arguments a r e different. then the value is *T* o r NIL depending upon whether the arguments a r e identical in their representation in core memory. Another consequence is that (QUOTE T) or (QUOTE X) is equivalent to T a s a constant predicate. the value of 3 is NIL.
1 Reading and Printing Numbers Numbers a r e stored in the computer a s though they were a special type of atomic symbol. Numbers may occur in S-expressions a s though they were atomic symbols. Fixed-Point Numbers These a r e written a s integers with an optional sign. 4. b . A plus sign o r minus sign may precede the number. The letter E followed by the exponent to the base 10 is written directly after the number. Examples -1 7 327 19 . Following a r e examples of correct floating-point numbers. 6 . 2. Absolute values must lie between 2' 28 and 2-I 28 and 5. These a r e all different forms for the same number. Numbers a r e constants that evaluate to themselves. Numbers should not be used a s variables o r function names. A decimal point must be included but not a s the first o r last character. This is not required when there is no ambiguity. This is discussed more thoroughly in section 7.ARITHMETIC LISP Lisp 1 . There a r e functions and predicates in the system for performing arithmetic and logical operations and making basic tests. 3. The exponent consists of one o r two digits that may be preceded by a plus o r minus sign. a r e incorrect because the decimal point is the first or last character respectively. Exponent indication i s optional. 3. Floating-Point Numbers The rules for punching these for the read program are: 1 . a . 4. 2.3. The forms . Significance is limited to 8 decimal digits. and will have the same effect when read in. The plus sign is not required. 5 has provision far handling fixed-point and floating-point numbers and logical words. Any possible ambiguity between the decimal point and the point used in dot notation may be eliminated by putting spaces before and after the LISP dot.6E+2 and 60. They do not need to be quoted. The following points should be noted : 1 .
The number is then stored a s a logical word. 2. If there is a negative sign.xn] is a function of any number of arguments whose value is the algebraic sum of the arguments. The rightmost digit is placed in bits 33-35. The accumulator is shifted left three bits (one octal digit) times the scale factor.. The arguments may be any type of number.c . then the value will be a fixed-point number. . no sign allowed. i t is OR-ed into the P bit. d. 4. 4.2 Arithmetic Functions and Predicates We shall now list all of the arithmetic functions in the System. Note that because the sign is OR-ed with the 36th numerical bit c.. Up to 12 digits (0 through 7). An optional scale factor. and e a r e equivalent. If all of the arguments for a function a r e fixed-point numbers. and 2. - . The examples a through e above will be converted to the following octal words. 3. plus[xl. Octal Numbers o r Logical Words The correct form consists of 1 . The letter Q. 3. A sign (optional). The number is placed in the accumulator three bits per octal digit with zeros added to the left-hand side to make twelve digits. 1. 1. the twelfth digit is placed in bits P . They must be given numbers a s arguments. . A function may be given some fixed-point arguments and some floating-point arguments a t the s a m e time. otherwise an e r r o r condition will result. 2. Thus the scale factor is an exponent to the base 8. The scale factor is a decimal integer. Example The effect of the read program on octal numbers is a s follows. If a t least one argument is a floating-point number. then the value of the function will be a floating-point number.
remainder[^. The reciprocal of any fixed point number is defined a s zero. ~ ] . fixp[x] is true only i f x is a fixed-point number. .y] is true i f x > y. The value is fixed-point or floating-point.^] has for i t s value the algebraic difference of its arguments. subl[x] has x-1 for its value. Note that max[xl.~ 3 X 10 . - .. zerop[x] is true i f x=O.- difference[^.xn] chooses the largest of its arguments for i t s value - max[3.2. "-0 is negative. depending on the argument. addl[x] has x t l for its value.x n ] performs a logical OR on its arguments. depending on the argument. We shall now list all of the arithmetic predicates in the System.xn] is a function of any number of arguments..^] computes the quotient of i t s arguments. o r they may be the result of a previous computation.. divide[x. - - - - 1 IC - I 1 .. this is computed by iter= ative multiplication. l e s ~ ~ [ xis ~ ] if x c y. and the floating-point residue for floating-point arguments. If x is not a number at all. . an e r r o r will result.^] computes the number theoretic remainder for fixed-point numbers. or if 1 x 3X onep[x] is true if x. . For fixed-point arguments.. times[xl. ..~]. The only acceptable arguments a r e fixed-point numbers.y] = cons[qu~tient[x. o n ~ [ r e m a i n d e r [ x .0] = 3.0. . . quo ti en![^.y] works on any arguments including S-expressions incorporating numbers inside them. equal[x. logor[xl . numberp[x] is true if x is a number (fixed-point or floating-point). ~ ~ ~ ] ] c e ~ p t [ x .. ~ ]xY. They may have fixed-point and floating-point arguments mixed freely. Otherwise the power is computed by using logarithms. whose value is the product . These may be read in a s octal o r decimal integers. Floating-point numbers -6 < must satisfy x . . The value of a predicate is *T* or NIL. The logical functions operate on 36-bit words. floatp[x] is similar to fixp[x] but for floating-point numbers. minus[x] has for its value -x. the value is the number theoretic quotient. Its value is true i f the arguments a r e identical.. If both x and y a r e fixed-point numbers. A divide check o r floating-point trap will result in a LISP e r r o r . true greaterp[x. The first argument cannot be negative. minusp[x] is true i f x is / negative.1 ( < 3 X lo-'. min[xl . . The value is fixed-point or floating-point. and false otherwise. recip[x] computes l/x. (with correct sign) of its arguments..xn] chooses the smallest of i t s arguments for its value.
its dimensions. atomic symbols or other S-expressions.3 Programming with Arithmetic The arithmetic functions may be used recursively.n] = x x 2".xn] performs an exclusive OR (OxO=O. . leftshift[x. to make an a r r a y called alpha of size 7 X 10. The data may consist of numbers.. 1 ~ 1 = 0 ) .. alpha and beta a r e now functions that can be used to set o r locate elements of these respective a r r a y s . T-n.) of For example.. . 1 ~ 0 = 0 ~ 1 = 1 . 3. just a s other functions available to the interpreter. . the first argument will be shifted right. As an example.4] . n! = [ n = 0 -1. 4.logand[xl . and the word LIST. Indices range from 0 to n-I. If the second argument is negative. and one called beta of size 3 X 4 X 5 one should execute: . Each element (uniquely specified by i t s coordinates) contains a pointer to an S-expression (see Section VII) array is a function of one argument which is a list of a r r a y s to be declared. - a r r a y [ ( ( A ~ p ~ A10) LIST) (BETA ( 3 4 5) LIST))] (7 After this has been executed. (Nonlist a r r a y s a r e reserved for future development~ the LISP system. Arrays may have up to three indices. we define factorial a s it was given in Section I. .. The first argument is shifted left by the number of bits specified by the second argument. to (A B C) execute - a l p h a [ s ~(A. logxor[xl . 4 The Array Feature Provision is made in LISP 1.B ~ c).(n-l)! ] DEFINE (( (FACTORIAL (LAMBDA (N) (COND ((ZEROP N) 1) (T (TIMES N (FACTORIAL (SUB1 N)))) ))) 4 . both a r r a y s exist and their elements a r e all set to NIL. and turns the name of an a r r a y into a function that can be used to fill the a r r a y or locate any element of i t . Each item is a list containing the name of an array. The pseudo-function a r r a y reserves space for arrays. to x. execute TO set alphai s j - To set alpha3.5 for allocating blocks of storage for data.xn] performs a logical AND on i t s arguments.
4]. specify dimensions in increasing order. use the a r r a y name a s a function with the coordinates a s axes. . Thus any time after executing the previous example - alpha[3. Storage for a r r a y s is located in an a r e a of memory called binary program space.4. and J bound to 4. in which case the setting can be done by evaluating - (ALPHA (QUOTE SET) X I J ) To locate an element of an array. ~eta[3.3.5]is better than beta[5. I bound to 3.Inside a function or program X might be bound to (A B C).4] = (A B C) Arrays use marginal indexing for maximum speed. For most efficient results.
Length is a function of one argurnentL. Store in cdr of what is now in g. The program uses two program variables u . u. In English the program is written: This is a function of one argument 1. which examines a list and decides how many elements there a r e in the top level of the list. This Rewriting this a s an S-expression. we get the following program. with a few new notations. Store 0 in Store the argument 1 in 2 . and the value is whatever is now in 2 . An example of the program feature is the function length. We now write this program a s an M-expression. The value of length is an integer.and y.one more than what is now in Go to A. corresponds line for line with the program written above. It is a program with two program variables 2 and 1. which can be regarded a s storage locations whose contents a r e to be changed by the program.V. DEFINE ( ( (LENGTH (LAMBDA (L) (PROG ( U V) (SETQ V 0) (SETQ U L) (COND ((NULL U) (RETURN V))) (SETQ U (CDR U)) (SETQ V (ADD1 V)) (GOA) 1)) 1) LENGTH ((A B C D)) . THE PROGRAM FEATURE The LISP 1 . 5 program feature allows the user to write an Algol-like program containing LISP statements to be executed. Store in 1. A If g contains NIL. then the program is finished.
like other LISP functions. i t returns with the value NIL. x:= cdr[x]. This is true only for conditional expressions that a r e on the top level of a PROG. The first list after the symbol PROG is a list of program variables.) An atomic symbol in the list is the location marker for the statement that follows. Their values a r e four and five. To set variable PI to 3. . To s e t a program variable. Executing a statement means evaluating it with the current a-list and ignoring i t s value.14). The function rev. The value of SET o r SETQ i s the value of its second argument.^]. (GO A) will cause the program to continue a t statement A.LENGTH (((X Y) A CAR (N B) (X Y 2))) The last two lines a r e test cases. which reverses a list and all its sublists is an example of this. Thus (SETQ PI 3. but they a r e not bound by LAMBDA. In the above example. can be used recursively. The value of each program variable is NIL until i t has been set to something else. The program feature. SET and SETQ can change variables that a r e on the a-list from higher level functions. Statements a r e normally executed in sequence. then this should be written NIL or (). If a program runs out of statements. A is a location marker for the statement beginning with COND. A [null[x]-return[y]. rev[x] = ~ r o g [ [ ~ . Conditional expressions a s program statements have a useful peculiarity. sequence of statements and atomic' symbols. Program variables a r e treated much like bound variables. SETQ is like SET except that it quotes its first argument. instead of an e r r o r indication which would otherwise occur. If there a r e none. No further statements a r e executed. z:= car[x]. GO is a form used to cause a transfer. If none of the propositions a r e true.go[^]]. The program form has the structure - (PROG. B z:= rev[z]. the program continues with the next statement. The form GO can be used only a s a statement on the top level of a PROG o r immediately inside a COND which is on the top level of a PROG. and this is the value of the program.14 write (SET (QUOTE PI) 3. respectively. [atom[z]. goiA11 The function rev will reverse a list on all levels s o that rev[(A ((B C) D))] = ((D (C B)) A) . list of program variables. RETURN is the normal end of a program. SETQ is usually more convenient. .14). z ] . The argument of RETURN is evaluated. use the form SET. Program statements a r e often executed for their effect rather than their value. y: = cons[^.
d: FIN card e: Two blank cards to prevent c a r d reader from hanging up The ID card may have any information desired by the computation center. Definitions and other memory changes made during a SET will affect all remaining packets. Several SET'S during a LISP run will s e t on top of each other. To prevent reading from continuing indefinitely. It will be - . FIN: End of LISP run. Some Overlord cards will now be described. control is returned to Overlord which r e s t o r e s the core memory to what it was before the TEST by reading in a core memory image from the temporary tape. Instead. and the comments field s t a r t s in column 16. RUNNING THE LISP SYSTEM 6 . o r until a read e r r o r occurs. Overlord direction c a r d s a r e punched in Share symbolic format. restoration of the system memory between packets. STOP will appear to be inside an S-expression and will not be recognized a s such. TEST: Subsequent doublets a r e read in until the word STOP is encountered. except that i t will set even if there is an e r r o r . and becomes the base memory for all remaining packets. The reading of doublets is normally terminated by the word STOP. a diagnostic w i l l be written and the program will continue with the next doublet. However. A complete card deck for a LISP run might consist of: a: LISP loader b: ID card (Optional) c: Several Packets . The memory will be restored from the temporary tape instead. A SET will not s e t if it contains an e r r o r . followed by a s e t of doublets for evalquote.VI. and ending with the word STOP. SETSET: This direction is like SET. SET: The doublets a r e read and interpreted in the same manner a s a TEST. each packet should end with STOP followed by a large number of right parentheses. 1 Preparing a Card Deck A LISP program consists of several sections called packets. If an e r r o r occurs. the core memory is written out onto the temporary tape (overwriting the previous core image). Overlord direction cards control tape movement. and core dumps. when all doublets have been evaluated. the core memory is not restored. An unpaired right parenthesis will cause a read e r r o r and terminate reading. When all doublets have been evaluated. Each packet s t a r t s - with an Overlord direction card. The doublets a r e then evaluated and each doublet with i t s value is written on the output tape. A complete listing of Overlord directions is given in Appendix E. If parentheses do not count out. the direction s t a r t s in column 8.
Interpreter E r r o r s : APPLIED FUNCTION CALLED ERROR A 1 The function e r r o r will cause an e r r o r diagnostic to occur. After trace has been executed. does not have a definition either on its property list o r on the a-list of apply. 2 Tracing Tracing is a technique used to debug recursive functions. in this case control is given to the monitor Overlord. The diagnostic gives the type of e r r o r . tracing will occur whenever these functions a r e entered. 6 . This i s a list of functions that were entered recursively but not completed a t the time of the e r r o r . In some cases a back-trace is also printed. In most casee. SETQ GIVEN ON NONEXISTEYT PROGRAM VARIABLE . UNBOUND VARIABLE EVAL The atomic symbol in question is not bound on the a-list for eval nor does it have an APVAL. and i t s value when it is finished. However. given a s the first argument of apply. certain e r r o r s a r e fatal. - - . A complete list of e r r o r diagnostics is given below. The t r a c e r prints the name of a function and i t s arguments when it is entered.printed at the head of the output. Tracing is controlled by the pseudo-function trace.APPLY This occurs when an atomic symbol. A 3 A A A A 4 5 6 7 A 8 CONDITIONAL UNSATISFIED EVCON None of the propostiions following COND a r e true. A 2 FUNCTION OBJECT HAS NO DEFINITION.APPLY GO REFERS TO A POINT NOT LABELLED . 6 . The argument (if any) of e r r o r will be printed. E r r o r is of some use a s a debugging aid. with comments.SPREAD The interpreter can handle only 2 0 arguments for a function. ' a diagnostic giving the nature of the e r r o r is printed out. it can be terminated by the pseudo-function untrace whose argument is a list of functions that a r e no longer to be traced.APPLY SET GIVEN ON NONEXISTENT PROGRAM VARIABLE .5 program. and the contents of certain registers at that time. the user can often locate a fault in a large program. When tracing of certain functions is no longer desrred. whose argument is a list of functions to be traced. By tracing certain critical subfunctions.INTER TOO MANY ARGUMENTS . the program continues with the next doublet. E r r o r s during Overlord also continue with Overlord. 3 E r r o r Diagnostics When an e r r o r occurs in a LISP 1 .
this e r r o r will occur.CONTINUING WITH NEXT EVALQUOTE When the instruction STR is executed. - Garbage Collector E r r o r s : GC 1 FATAL ERROR RECLAIMER This e r r o r only occurs when the system is s o choked that it cannot be restored. - Compiler E r r o r s : C 1 CONDITION NOT SATISFIED IN COMPILED FUNCTION Character -Handling Functions : CH 1 TOO MANY CHARACTERS IN PRINT NAME PACK FLOATING POINT NUMBER OUT OF RANGE . - - Miscellaneous E r r o r s : F 1 CONS COUNTER TRAP The cons counter is described in section 6. F 2 FIRST ARGUMENT LIST TOO SHORT .PAIR F 3 SECOND ARGUMENT LIST TOO SHORT PAIR P a i r is used by the interpreter to bind variables to arguments. FLOATING POINT TRAP OR DIVIDE CHECK OUT OF PUSH DOWN LIST The push-down l i s t is the memory device that keeps track of the level of r e cursion. these e r r o r s may occur. - - Arithmetic E r r o r s : I 1 NOT ENOUGH ROOM FOR ARRAY Arrays a r e stored in binary program space. GC 2 NOT ENOUGH WORDS COLLECTED RECLAIMER This e r r o r r e s t o r e s f r e e storage a s best i t can and continues with the next doublet. Control goes to Overlord. If sense switch 6 is down when an STR is executed.A 9 FUNCTION OBJECT HAS NO DEFINITION EVAL Eva1 expects the f i r s t object on a list to be evaluated to be an atomic symbol. - F 5 G 1 G 2 STR TRAP .4. If a function is given the wrong number of arguments. this e r r o r occurs. . A 8 and A 9 frequently occur when a parenthesis miscount causes the wrong phrase to be evaluated. When recursion becomes very deep. Nonterminating recursion will cause this e r r o r .NUMOB CH 2 CH 3 TAPE READING ERROR ADVANCE The character-handling functions a r e described in Appendix F. control goes to Overlord instead.
EXPT E r r o r s I 3 and I 4 will occur when numerical functions a r e given wrong arguments. R 6 NUMBER TOO LARGE IN CONVERSION RDA - - 6." out of context. Lap E r r o r s : L 1 UNABLE TO DETERMINE ORIGIN L 2 OUT OF BINARY PROGRAM SPACE UNDEFINED SYMBOL L 3 L 4 FIELD CONTAINED SUB SUBFIELDS - Overlord 0 1 0 2 0 3 0 4 0 5 0 7 Errors: ERROR IN SIZE CARD . It automatically causes a t r a p when a certain number of conses have been performed. The counter is turned on by executing count [n]. CONTEXT ERROR WITH DOT NOTATION .OVERLORD INVALID TAPE DESIGNATION OVERLORD NO SIZE CARD . The counter can be turned on s o a s to continue counting from the state i t was in when last turned off by executing count [NIL]. The counter is turned off by uncount [NIL].RDA R 3 R 4 END OF FILE ON READ-IN RDA PRINT NAME TOO LONG . a trap will occur and an e r r o r diagnostic will be given.FIXVAL .I 2 I 3 I 4 FIRST ARGUMENT NEGATIVE BAD ARGUMENT .OVERLORD BAD INPUT BUT GOING ON ANYHOW . where n is an integer.RDA R 2 ILLEGAL CHARACTER .OVERLORD BAD DUMP ARGUMENTS .NUMVAL BAD ARGUMENT . .SETUP - Input -Output E r r o r s : PRINl ASKED TO PRINT NON-OBJECT P 1 FIRST OBJECT ON INPUT LIST IS ILLEGAL .4 The Cons Counter and E r r o r s e t The cons counter is a useful device for breaking out of program loops. The counter is turned on and r e s e t each time count [n] is executed.OVERLORD OVERLAPPING PARAMETERS . If n conses a r e performed before the counter is turned off.RDA R 1 This e r r o r occurs when the read program encounters a character such'as I1)l1o r . This occurs frequently when there is a parenthesis miscount. The function speak [NIL] gives the number of conses counted since the counter was last reset.RDA R 5 Print names may contain up to 30 BCD characters.
m.is the number of conses permitted before a cons trap will occur.a] = list[eval[e.a] is a pseudo-function with four arguments. then e r r o r s e t can be defined by errorset[e. and if no damage has been done by pseudo-functions. i t may be possible to continue computation in a different direction when one path results in an e r r o r . When an e r r o r occurs inside an e r r o r s e t . The cons counter is always on during an e r r o r s e t . If no e r r o r occurs. however. but will not be printed if m is NIL.n. .m. If variables bound outside of the e r r o r s e t have not been altered by using cset o r set. errorset[e.e r r o r s e t is a function available to the interpreter and compiler for making a graceful r e t r e a t from an e r r o r condition encountered during a subroutine. the e r r o r diagnostic will occur if m is s e t true. then the value of e r r o r s e t is NIL.a]] n .n. The on-off status of the counter w i l l also be restored. If an e r r o r occurs inside of an e r r o r s e t . when leaving the e r r o r s e t the counter is always restored to the value i t had before entering the e r r o r s e t .
add. In this section.-- -F] . Suppose the decrement of word x contains a pointer to word y. Each of these is a 15-bit field of the word.-instead of . 7. We define a pointer to a computer word a s the 15-bit quantity that is the complement of the address of the word. Following a r e some diagrammed S-expressions. but a s structural forms built out of computer words a s parts of trees. the atomic symbol will be written there as 1 : The rule for representing non-atomic S-expressions i s to start with a word containing a pointer to car of the expression in the address. LIST STRUCTURES In other sections of this manual. we discuss the representation of lists inside the computer. representation of numbers. The representation of atomic symbols will be explained in section 7 . the nature of property lists of atomic symbols. We diagram this a s We can now give a rule for representing S-expressions in the computer. . When a computer word contains a pointer to an atomic symbol in the address or decrement. 1 Representation of List Structure Lists a r e not stored in the computer a s sequences of BCD characters. the address and decrement. 3 . Thus a pointer to location 77777 would be 00001. In representing list structure.VII. shown as they would appear in the computer. a computer word will be depicted as a rectangle divided into two sections.. and the garbage collector. I dec. and a pointer to c r of the expression & in the decrement. lists have been discussed by using the LISP inputoutput language. It i s convenient to indicate NIL by -.
Therefore. however. and C a r e represented by pointers to locations 12327. N) X (M . they can occur inside the computer a s the result of computations involving certain functions. . 12330. Their printed representation i s infinite in length. it is difficult to arrange blocks of 37 .It is possible for lists to make use of common subexpressions. NIL is represented by a pointer to location 00000..N)) Circular lists a r e ordinarily not permitted. and 12331. . A)) The atoms Aj B. respectively. For example. ((M could also be represented a s . The advantages of list structures for the storage of symbolic expressions are: 1. the structure will print a s (A B C A B C A. That which follows i s an actual assembly listing of the S-expression (A (B (C (C A)) which i s diagrammed: . They may not be read in. The size and even the number of expressions with which the program will have to deal cannot be predicted in advance.
= ((A (Bc ) ) (D (E F)). 7 .(XY z)). and a function for deriving one from the other is given in LISP. Even one register returned to the list is of value. which is represented a s and that we wish to construct a list of the form 1. .-storage list when they a r e no longer needed.. An expression that occurs a s a subexpression of several expressions need be represented in storage only once. . . Two types of list structures a r e shown. .(x (Y z))) . but i f expressions a r e stored linearly.. We assume that we have a list of the form n. 2 Construction of List Structure The following simple example has been included to illustrate the exact construction of list structures. Registers can be put back on the free. 2. it is difficult to make use of blocks of registers of odd s i z e s that may become available. which is represented a s .. = ((A B C ) (DE F).storage of fixed length t o contain them. 3.
. (A (B C)) of the second list Q2. grp For this purpose. given a list. a property list i s created for it. NIL]] cons [~. Each property i s preceded by an atomic symbol which is called its indicator. When an atomic symbol i s read in f o r the first time. x.cons[cons CO~S[C. a new function. B. of three atomic symbols. the arguments A. grp[x] = list[car[x].T cons[grp[car[P]]. The rest of the list contains various properties of the atomic symbol. m.We consider the typical substructure. - - 7.its PNAME. Permanent value for the atomic symbol considered a s a variable. (X (Y Z)) until the list P1 has been exhausted and the new list P2 achieved. using the l function. and C by the operation [B.caddr[x]]] Then -is used on the list P1. of three arguments which creates (X (Y Z)) from a list of the form (X Y Z). x = (A B C). Its property list looks like this: .3 Property Lists In other sections. in turn and applies grp to it to put it in the new form. (X Y Z). Some of the indicators are: PNAME EXPR SUBR APVAL - - the BCD print name of the atomic symbol for input-output use. minus 1) a s the first element of the list. B.list[cadr[x]. This may be constructed from A. e . Function defined by a machine language subroutine. and an APVAL that gives it a value of NIL. and C to be used in the previous construction a r e found from A = car[x] B = cadr[x] C = caddr[x] The first step in obtaining P2 from P1 is to define a function. under the assumption that P1 i s of the form given. S-expression defining a function whose name is the atomic symbol on whose property list the EXPR appears. atomic symbols have been considered only a s pointers.mltgrp[cdr[~]]]] So rnltgrp applied to the list P1 takes each threesome. Every atomic symbol has a property list. mltgrp. A property list is characterized by having the special constant 777778 (i. In this section the property lists of atomic symbols that begin at the appointed locations a r e described. or. - The atomic symbol NIL has two things on its property list . we can write the same thing a s & In any case.NIL]]. i s defined a s mltgrp[P] = [null[P] NIL.
2 1 The indicator EXPR points to an S-expression defining a function. The last word of the print name is filled out with the illegal BCD character 778 ( 7 ) . -NIL -APVAL.. *-2 -*0 -PNAME . i t s property list would look like this -1 I I LAMBDA .. F o r example TXL 37721. . The function define puts EXPR1s on property lists.-*-I 1. . After defining ff.-1 A I APVAL I 1 I PNAME~ I NIL??? .I .1 BCD NIL??? The print name (PNAME) is depressed two levels to allow f o r names of more than six BCD characters. . The print name of EXAMPLE would look like this: --- PNAME I I I + EXAMPL The property list of a machine-language function contains the indicator SUBR followed by a TXL instruction giving the location of the subroutine and the number of arguments. 1 1 -*-*- -*-.
would~ ] (LAMBDA (X) (COW.i] can be used to put any indicator on a property list. consider the function mltgrp of section 7 . 2 . The function deflist[x. define[x] = deflist[x. This word consists of a word with -1 in the address. 7. The only basic function that affects list structure is cons. F o r example. Unlike atomic symbols. numbers a r e not stored uniquely.4 List Structure Operators The theory of recursive functions developed in Section I will be referred to a s elementary LISP. This is a list-altering . As an example. flag Numbers a r e represented by a type of atomic symbol in LISP. but make the modifications while copying the original. such a s equal and subst. and a pointer to the number itself in the decrement of this word. Its value is x. The value of g e t [ ~ ~ . the flag TRACE is a signal that a function is to be traced. a s well a s f o r their value. the second argument is the indicator to be used.. but creates new lists. They can be used to create circular lists.y] replaces the address of x with y. They a r e used for their effect. rplaca can be described by the equation r p l a ~ a [ x . Functions written in pure LISP such a s subst do not actually modify their arguments.i] can be used to find a property of x whose indicator i s i. certain bits in the tag which specify that it is a number and what type it is. LISP is made general in t e r m s of list structure by means of the basic list operators rplaca and rplacd. i t is not convenient a s a programming system without additional tools to increase its power. Flags can be put on property l i s t s and removed by using the pseudo-functions -and rernflag. ~ G be A property with i t s indicator can be removed by remprop[x. They can permanently alter existing definitions and other basic memory. and a r e called pseudo-functions.y] replaces the decrement of x with y.i]. In t e r m s of value. Although this language is universal in t e r m s of computable functions of symbolic expressions.The function get[x. the decimal number 15 is represented a s follows: . c d r [ x ] ] = But the effect is quite different: there is no cons involved and a new word is not created. which can cause infinite printing. rplacd[x.Ex~R]. In particular. The f i r s t argument is a list of pairs a s for define. and this does not change existing lists. elementary LISP has no ability to modify list structure. F o r example. rplaca[x. These operators can be used to replace the address o r decrement o r any word in a list. An indicator on a property list that does not have a property following it is called a flag. These operators must be used with caution. but x is something different from what it was before. ~ ]c ~ n s [ ~ . and look infinite to functions that search.
and uses four cons's. This is done by r p l a c d [ c d r [ x ] . A certain register.cons[cadr[x]. - 7. but grp -can be rewritten by using rplaca and rplacd.~ r o g 2 [ ~ g ~ ~ [ c a r [ ~ I l ~ ~ ~ ~ t g r ~ [ c d r [ ~ 1 1 1 1 prog2 is a function that evaluates i t s two arguments. Therefore a new mltgrp is needed that executes pgrp and ignores its value. The remaining registers a r e arranged in a single list called the free-storage list.~l~] The function -is used entirely for its effect.r e pseudo-functions. The other modification is to break the pointer from the second to the third word. pgrp and . pmltgrp a The value of pmltgrp is NIL. Because there a r e only three words in the original. pmltgrp[l] = [null[l] -. FREE. at leaSt one cons is necessary. A pointer to it is provided by rplaca[cdr[x]. the f i r s t word on the free-storage list is taken and the number in register FREE is changed to become the location of the second word on the free-storage . in the program contains the location of the f i r s t register in this list.cddr[x]]]. ~ l ~ ] . The subfunction -rearranges a subgroup grp The original function does this by creating new list structures.function that alters a copy of its argument. When a word is required to form some additional list structure. - T -.cons[cadr[x].5 The Free-Storage List and the Garbage Collector At any given time only a part of the memory reserved for list structures will actually be in use f o r storing S-expressions. pgrp -is now defined a s pgrp[x] = rplacd[rplaca[cdr[x]. Since the top level is not to be copied. The modification is The new word is created by cons[cadr[x]. mltprp should do no consing.cddr[x]]. NIL.cddr[x]]]. Its value is not useful. being the pgrp substructure ((B C)). Its value is the second argument.
No provision need be made for the user to program the return of registers to the free-storage list. First. This return takes place automatically whenever the free -storage list has been exhausted during the running of a LISP program. Whenever a negative register i s reached in a chain during this process. These problems a r e solved by putting full words in a reserved section of memory called full-word space. The garbage collector must also stop tracing because the pointers in the address and decrement of a full word a r e not meaningful. etc. The garbage collector stops tracing a s soon a s it leaves the free-storage space. Any piece of list structure that i s accessible to programs in the machine i s considered an active list and is not touched by the garbage collector. i. The list structures involved may be arbitrarily long but each register that is active must be connected to a base register through a cdr chain of registers. The program that retrieves the storage is called the garbage collector. therefore its contents are no longer of interest. the registers that contain partial results of the LISP computation in progress. every active register that can be reached through a car-cdr chain is marked by setting its sign negative. inaccessible. such a s the registers in the list of atomic symbols. Then the garbage collector does a linear sweep of the free-storage area. registers are reclaimed for the free-storage list by the garbage collector a s follows. The garbage collector cannot mark these words because the sign bit may be in use. Marking in full-word space i s accomplished by a bit table. --- car- . The active lists a r e accessible to the program through certain fixed sets of base registers. The nonactive. e. the garbage collector knows that the r e s t of the list involving that register has already been marked.list. and restoring the original signs of the active registers. Any register that cannot be s o reached is not accessible to any program and is nonactive. Sometimes list structure points to full words such as BCD print names and numbers. . collecting all registers with a positive sign into a new free-storage list.
. in particular. junction). . Wang. p is a string and a p is a sequent single formula) and which.THE WANG ALGORITHM FOR THE PROPOSITIONAL CALCULUS This section gives an example of a complete collection of LISP function definitions which were written to define an algorithm. One need only reflect on the intuitive meaning of the truth functions and the arrow sign to be convinced that these rules a r e indeed correct. If 4. and of their consistency. As a proof procedure in the usual sense. e. "A propositional letter P. a r e formulae. the conjunction of all formulae in the antecedent implies the disjunction of all formulae in the consequent. Initial rule: i f h. The program was then run on several test cases. January 1960. and is then written in M-expressions. all provable sequents a r e intuitively valid. it is preferable to use more logical connectives to begin with when we wish actually to apply the procedure to concrete cases. all intuitively valid sequents a r e provable. 5 a r e strings of atomic formulae. e . (biconditional). then & V 43 f a r e formulae. is a theorem i f "In the ten r u l e s listed below. a proof will be given of their completeness. The algorithm itself is explained. h and 5 a r e always strings (possibly empty) of atomic formulae. with their usual interpretations. e .E. Develop. might be an empty string o r a is a formula. We quote from pages 5 and 6 of Wangls paper: "The propositional calculus (System P ) Since we a r e concerned with practical feasibility. each proof begins with a finite s e t of cases of P1 and continues with successive consequences obtained by the other rules . Res. i. "Toward Mechanical Mathematics. " P I . A COMPLETE LISP PROGRAM . Vo1. Q. The complete input card deck an'd the printed output of the run a r e reprinted h e r e . et cetera. . If n. "There a r e eleven rules of derivation. + +. F o r this purpose we use the five usual logical constants (not). intuitively speaking. Hao. + +. then h some atomic formula occurs on both sides of the arrow. No.VIII. The reader will need to know something about the propositional calculus in order to understand this discussion. + + + +. & (conjunction).. - - . +.5 . There a r e two rules for each of the five truth functions one introducing i t into the antecedent. one introducing i t into the consequent. Later on. .V + N +. then IT. p a r e strings of formulae (each." IBM J. i .I1 1. 1. is true if and only if either some formula in the string n (the I1antecedentI1)is false o r some formula in the string p (the llconsequent") is true. The Wang Algorithm 1 is a method of deciding whether o r not a formula in the propoditional calculus is a theorem.4. i. M o r N. R. V (dis3(implication). is a formula (and an "atomic formulat1). An initial rule states that a sequent with only atomic formulae (proposition letters) is a theorem if and only if a same formula occurs on both sides of the arrow. .
+. . Q VALID ---P& & Q . P5a. 5 . by the initial rule. .+. then 5 -. taken together.p -a. Each connective-free sequent can then be tested for being a theorem or not. t h e n h .p.P 5 Q.Q -P Q. p-a.& : Rule & . N Q . though not necessary. For example: *2. P S Q can be rewritten and proved a s follows: *2. Q VALID (5) Q -Pa P .. then X. thereby resulting in one or two premises which.P . otherwise we get a counterexample and a disproof. We shall. +: (PVQ) 3 . ( ~ & ~ ~ l . P4b. then 5 -h.+. ~ + . given any theorem of nPrincipia. p . p +. then h a + & + P-a.P E Q (2)"P. p a n d 5 -h. ~ h. i t is arrow to it and apply the rules to look for a proof. simpler."As w i l l be explained below. /v . p.0 .45. "For example.+.+. P. Some simple samples w i l l make this clear. we can find the first logical connective. and apply the appropriate rule to eliminate it.+.(SVICl1p ha+. a proof looks like a tree structure growing in the wrong direction. 5 -. t h e n S * h . ~ + p .P .I.P Q (3). 2 . t h e n S .V : RuleV -.P = (4) . to replace the main connective by an arrow and proceed.r a n d h.+V+. p d hap -a.h . we can automatically prefix an When the main connective is 3 .+. + -h.45. (3) P .p. +3+. A. : Rule-3 : .P. y : If If If If If If If 5 -hap. (P). . then the original sequent is a theorem and we obtain a proof.)w P -& P a P V Q (2) P -Pi"Q (1) *5. thereby incorporating the process of searching for a proof.p-a. P4a. This process can be repeated until we reach a finite s e t of sequents with atomic formulae only. Q (l)-P&w Q . Q VALID P2a. If all of them a r e theorems. P .: Rule -. a r e equivalent to the conclusion.21. P3a.+. Q (5) P -Q. + : N P &N Q .A.21. 3 . Rule Rule&--: Rule . be chiefly interested in doing the step backwards. P2b. *5. 5 -A. however. .a .+. "The rules a r e s o designed that given any sequent. P3b.
Rule= -: If + .+&51 becomes (AND +*) becomes (OR S*) 3. p .c] V [atom[car[ a]] thl [[member[car[a]. 1. p and 5 A +. P6a.+.+3JC. becomes (NOT +*) 2. The sequent is represented by the S-expression where in each case the ellipsis denotes missing terms.a . The following table gives our "Cambridge Polish" way of representing propositional formulae with given main connectives.then 5 . +a+. . is represented by (ARROW ((AND (NOT P ) (NOT Q))) ((EQUIV P Q) (OR R S))) The S-function theorem[s] is given in t e r m s of auxiliary functions a s follows: theorem[s] = thl [ N I L .cdr[a].a .. . # . p . P : If 4.+ 3 # +. 2.c].[ . Rule 3.a2] a2. We define a function theorem[s] whose value is truth o r falsity according to whether the sequent s is theorem. p . Rule P6b.+ v $ becomes (IMPLIES #*) 4. then h .cdr [a]. N I L . + 4.a .T cons[ c a r [a].: If h. +* -+ +* +* 5 .caddr[s]] [s] member[car[a]. # .al ] a1 .~]]] - +* @* +*) - - . + = + becomes (EQUIV Thus the sequent P & N Q . For "atomic formulaeu (Wang's terminology) we use "atomic symbols1' (LISP terminology).p-a.a2]].al]]. + .. then h.P5b.- .a a n d h. C ~ ~ ~.a2.P . - - (2) The LISP Program.RVS . and where denotes the S-expression for Propositional formulae a r e represented a s follows: 1. b h. + . " - - +.thl [al.~ . member[car[a].P = Q. +. pus and A p . h .T -c cons[car[ a].
c l. . According to whether the formula to be reduced is on the left o r right we use or g .c 1. c a r [c]. T e r r o r [ ~ ~ ~ .c2] .a2. .c 1.a2. car[u] = EQUIV .th2l[cdr[u].c2] A thlL caddr [u].a2.c2]]] .cdr[c2]].c 1.c 1.al .a2.al . car[u] = OR th2r[cdr[u]. a1 . null[c2]~thr[car[c2]. car[u] = OR thlQ[cadr[u].thl 1[cadr[u]. car[u] = AND thlr[cadr[u].cl .~.a2.caddr[u].a2. car[u] = IMPLIES thl 1[cadr[u].c2] = [ car[u] = NOT th1 r[cadr[u].cl.- - -- .al . We have tke[u.c 1.c2].al .c2].c 1.c2.al .c2] f i t h l r cadr[u].al .a2.al .cl . car[u] = EQUIV th2P [cdr[u].al .cl .c 1.c 1.cdr[a2].cl .a2.al.a2.a2.c2] = [null[a2] n.T cons[ .cl.c 1. .tke[car[a2].a2. u.c2].c2]. theorem. a1 .al .c2] A t h l r caddr[u].al.c2].a2.c2]]] .a2.al . t u a n d a 2 break up and s o r t the information in the sequent for the benefit of &. The four arguments oft& are: a l : atomic formulae on left side of arrow a2: other formulae on left side of arrow c l : atomic formulae on right side of arrow c2: other formulae on right side of arrow The atomic formulae a r e kept separate from the others in order to make faster the detection of the occurrence of formula on both sides of the arrow and the finding of the next formula to reduce.al .a2.cl .a2. The forumla to be reduced is chosen from the left side of the arrow if possible. u.a2.a2.al.caddr[u].c2] .al - - - - - - - - thr[u.cdr[c]]. car[u] = AND .a2.a2.a2.~ th2[al .c2] = [ car[u] = NOT .c2].a2.cl. car[u] = IMPLIES thll[caddr[u].c2] A th2r cdr[u].al .al.cdr [c]]] th[al .al .c2].cadr[u].cl. Each use of& represents one reduction according to one of the 10 rules.thl4[cadr[u].a2.c2].c 1. T e r r o r [ l i s t [ ~ ~ ~ .al .c 1. thl 1[caddr[u].c2]] t h i s the main predicate through which all the recursions take place.[ member[car[c].c 1.c2].c2].c 1.c 2]].c2.
c 2 ] .cl . The entire card deck is reprinted below.c2]] Finally the function member . t h l r . omitted. t h l l distribute the parts of the reduced formula to the appropriate places in the reduced sequent. v 2 . c l ] ~ ] thlr[v2.al .cons[car[v].c2] = [atom[car[v]] member[car[v]. a l .cons[vl. c 2= [atom[vl] .a 1.a2.a2.a2. TEST LISP.a2].0 WANG ALGORITHM FOR THE PROPOSITIONAL CALCULUS DEFINE(( (THEOREM (LAMBDA (S) (TH1 NIL NIL (CADR S) (CADDR S)))) . th28. which a r e binary.cdr [u]]] [x.c 1.a2].cl.a2. 2.c 1. The function member is not defined because it is already in the system.c2] v thld[cadr[v].al .c 1 .a2.cons[vl .c2] = [atom[car[v]] member[car[v]. ~ member[ -c a r [v]. TEST.al .c 1.c 11v thlP[cadr[v].~ . c l .is defined by member [ x.250.The functions thld.a2] V thl r [cadr [v].c2].3.cons [car [v].m e m b e r [ v l .cons[car[v]. with only the two loader cards.m e m b e r [ v l .cl]. c 2 ] ~ thl r[v2.al .~ member[V c a r [v].c2]] th2r [v.a2.c 2111 - - t h l ~ [ ~ l . These functions a r e th2l[v.cons[car[v].c2]. * M948-1207 LEVIN. a 2 .al .u] = ~ l u l l [ u ] ~ [ e ~ u a lcar[u]]\lmember [x.al] v thl r[cadr[v].al].c 1. th2r.al].
( T H l (LAMBDA (A1 .A2 A C ) (COND ((NULL A) (TH2 A1 A2 NIL NIL C ) ) ( T (OR (MEMBER (CAR A) C ) (COND ((ATOM (CAR A)) (TH1 (COND ((MEMBER (CAR A) A l ) A l ) ( T (CONS (CAR A) A l ) ) ) A2 (CDR A) C)) ( T (TH1 A1 (COND ((MEMBER (CAR A) A2) A2) ( T (CONS (CAR A) A2))) (CDR A) C)))))))) (TH2 (LAMBDA (A1 A2 C 1 C 2 C ) (COND ((NULL C ) ( T H A1 A2 C l C2)) ((ATOM (CAR C)) (TH2 A1 A2 (COND ((MEMBER (CAR C) C1) C1) ( T (CONS (CAR C ) C l ) ) ) C 2 (CDR C))) ( T (TH2 A1 A2 C 1 (COND ((MEMBER (CAR C) C2) C2) ( T (CONS (CAR C ) C2))) (CDR C)))))) (TH (LAMBDA (A1 A2 C 1 C2) (COND ((NULL A2) (AND (NOT (NULL C2)) (THR (CAR C2) A1 A2 C 1 (CDR C2)))) ( T ( T H L (CAR A2) A1 (CDR A2) C l C2))))) ( T H L (LAMBDA ( U A1 A2 C 1 C2) (COND ((EQ (CAR U) (QUOTE NOT)) ( T H l R (CADR U) A1 A2 C 1 C2)) ((EQ (CAR U) (QUOTE AND)) (TH2L (CDR U) A1 A2 C 1 C2)) ((EQ (CAR U) (QUOTE OR)) (AND ( T H l L (CADR U) A1 A2 C 1 C2) ( T H l L (CADDR U) A1 A2 C l C2) )) ( ( E Q (CAR U) (QUOTE IMPLIES)) (AND ( T H l L (CADDR U) A1 A2 C1 C2) ( T H l R (CADR U) A1 A2 C1 C2) )) ((EQ (CAR U) (QUOTE EQUIV)) (AND (THZL (CDR U) A1 A2 C1 C2) (THZR (CDR U) A1 A2 C 1 C2) )) ( T (ERROR (LIST (QUOTE THL) U A1 A2 C1 C2)))
(THR (LAMBDA (U A1 A2 C 1 C2) (COND ((EQ (CAR U) (QUOTE NOT)) (TH1 L (CADR U) A1 A2 C 1 C2)) ((EQ (CAR U) (QUOTE AND)) (AND ( T H l R (CADR U) A1 A2 C1 C2) ( T H l R (CADDR U) A1 A2 C l C2) )) ((EQ (CAR U) (QUOTE OR)) (THZR (CDR U) A1 A2 C1 C2))
((EQ (CAR U) (QUOTE IMPLIES)) ( T H l 1 (CADR U) (CADDR U)
A1 A2 C1 C2)) ((EQ (CAR U) (QUOTE EQUIV)) (AND (TH11 (CADR U) (CADDR U) A1 A2 C1 C2) ( T H l 1 (CADDR U) (CADR U) A1 A2 C1 C2) )) ( T (ERROR (LIST (QUOTE THR) U A1 A2 C 1 C2)))
( T H l L (LAMBDA (V A1 A2 C1 C2) (COND ((ATOM V) (OR (MEMBER V C1) (TH (CONS V A l ) A2 C1 C2) )) ( T (OR (MEMBER V C2) (TH A1 (CONS V A2) C1 C2) ))
( T H l R (LAMBDA (V A1 A2 C1 C2) (COND ((ATOM V) (OR (MEMBER V A l ) (TH A1 A2 (CONS V C1) C2) )) ( T (OR (MEMBER V A2) (TH A1 A2 C 1 (CONS V C2))))
(TH2L (LAMBDA (V A1 A2 C1 C2) (COND ((ATOM (CAR V)) (OR (MEMBER (CAR V) C1) ( T H l L (CADR V) (CONS (CAR V) A l ) A2 C 1 C2))) ( T (OR (MEMBER (CAR V) C2) ( T H l L (CADR V) A1 (CONS (CAR V) A2) C1 C2)))
(TH2R (LAMBDA (V A1 A2 C l C2) (COND ((ATOM (CAR V)) (OR (MEMBER (CAR V) A l ) ( T H l R (CADR V) A1 A2 (CONS (CAR V) C 1) C2))) ( T (OR (MEMBER (CAR V) A2) ( T H l R (CADR V) A1 A2 C1 (CONS (CAR V) C2))))
(TH11 (LAMBDA (V1 V2 A1 A2 C1 C2) (COND ((ATOM V1) (OR (MEMBER V1 C1) ( T H l R V2 (CONS V1 A l ) A2 C 1 C2))) ( T (OR (MEMBER V1 C2) ( T H l R V2 A1 (CONS V1 A2) C1 C2)))
T R A C E ((THEOREM TH1 TH2 TH T H L THR T H l L T H l R THEL TH2R TH11)) THEOREM ((ARROW ( P ) ((OR P Q)))) UNTRACE ((THEOREM TH1 TH2 THR T H L T H l L T H l R THZL THZR TH11))
THEOREM ((ARROW ((OR A (NOT B))) ((IMPLIES (AND P Q) (EQUIV P Q))) )) STOP))) FIN
M948- 1207 LEVIN
END O F LISP RUN
T h i s r u n produced t h e following output:
LEVIN, LISP, TEST, 2 , 3 , 2 5 0 , 0 WANG ALGORITHM FOR THE PROPOSITIONAL CALCULUS TEST THE TIME (8/ 8 1506.1) HAS COME, THE WALRUS SAID, T O TALK O F MANY THINGS . - LEWIS CARROLL -
HAS B E E N ENTERED, ARGUMENTS..
[ T h e c o m p l e t e list of definitions r e a d i n is omitted t o s a v e space.]
END O F EVALQUOTE, VALUE IS.. (THEOREM T H l TH2 TH T H L THR T H l L T H l R TH2L TH2R TH11) FUNCTION EVALQUOTE HAS B E E N ENTERED, ARGUMENTS..
TRACE ((THEOREM TH1 TH2 T H T H L THR T H l L T H l R T H 2 L THZR TH11)) END O F EVALQUOTE, VALUE IS. NIL FUNCTION THEOREM EVALQUOTE HAS B E E N ENTERED, ARGUMENTS..
ARGUMENTS O F TH1 NIL NIL (P) ((OR P Q)) ARGUMENTS O F TH1 (PI NIL NIL ((OR P Q)) ARGUMENTS O F THZ (PI NIL NIL NIL ((OR P Q)) ARGUMENTS O F TH2 (PI NIL NIL ((OR P Q)) NIL ARGUMENTS O F TH (PI NIL NIL ((OR P Q)) ARGUMENTS O F THR (OR P Q) (PI NIL NIL NIL ARGUMENTS O F THZR ( P Q) .
VALUE IS NIL FUNCTION EVALQUOTE HAS B E E N ENTERED. THEOREM ((ARROW ((OR A (NOT B))) ((IMPLIES (AND P Q) (EQUIV P Q ))))) .(PI NIL NIL NIL VALUE O F TH2R *T* VALUE O F THR *T* VALUE O F T H *T* VALUE O F TH2 *T* VALUE O F TH2 ST* VALUE O F TH1 *T* VALUE O F TH1 *T* END O F EVALQUOTE. VALUE IS.. *T* FUNCTION EVALQUOTE HAS B E E N ENTERED.. ARGUMENTS. UNTRACE ((THEOREM TH1 TH2 THR T H L T H l L T H l R THZL TH2R THl1)) END O F EVALQUOTE. ARGUMENTS.. ..
ARGUMENTS O F TH NIL ((OR A (NOT B))) NI L ((IMPLIES (AND P Q) (EQUIV P Q))) ARGUMENTS O F TH (A) NIL NIL ((IMPLIES (AND P Q) (EQUIV P Q))) ARGUMENTS O F TH (A) ((AND P Q)) NIL ((EQUIV P Q)) ARGUMENTS O F TH (Q P A) NIL NIL ((EQUIV P Q)) VALUE O F TH *T* VALUE O F TH *T* VALUE O F TH *T* ARGUMENTS O F TH NIL ((NOT B)) NIL ((IMPLIES (AND P Q) (EQUIV P Q))) ARGUMENTS O F TH NIL .
NIL (B) ((IMPLIES (AND P Q) (EQUIV P Q)) ARGUMENTS O F TH NIL ((AND P Q))
((EQUIV P Q)) ARGUMENTS O F TH (Q P ) NIL (B) ((EQUIV P Q ) ) VALUE O F TH *T* VALUE O F TH *T* VALUE O F TH
VALUE O F TH *T* VALUE O F TH *T* END O F EVALQUOTE, VALUE I S . . *T* THE TIME (8/ 8 1506.3) HAS COME, T H E WALRUS SAID, T O TALK O F MANY THINGS
. . . - LEWIS CARROLL -
END O F EVALQUOTE OPERATOR FIN END O F LISP J O B END O F LISP RUN M948-1207 LEVIN
FUNCTIONS AND CONSTANTS IN THE LISP SYSTEM This appendix contains all functions available in the LISP System a s of August 1962. Each entry contains the name of the object, the property under which it is available (e. g., EXPR, FEXPR, SUBR, FSUBR, o r APVAL), whether it is a pseudo-function, functional (function having functions a s arguments), o r predicate, and in some c a s e s a definition of the function a s an M-expression. In the case of APVALts, the value is given. The LISP Library is a file of BCD cards distributed with the LISP System. It is not intended to be used a s input to the computer without being edited first. Have the Library file punched out, and then list the cards. Each Library function is preceded by a title card that must be removed. Some Library entries a r e in the form of a DEFINE, while some a r e in the form of an assembly in LAP. Note that some of them have auxiliary functions that must be included. Elementary Functions car -[x] cdr -[x] SUBR SUBR
r The elementary functions car and & always have some s o r t of value rather than applied to an atomic symbol will allow one giving an e r r o r diagnostic. A chain of & I s to s e a r c h i t s property list. Indiscriminate use of these functions past the atomic level will result in non-list structure and may appear a s lengthy o r even infinite garbage expressions if printed.
CAR SXA PDX CLA PAX PXD AXT TRA SXA PDX C LA PDX PXD AXT TRA CARX, 4 094 0,4 084 0,4 4
CDRX, 4 O,4 0,4 0,4 0,4 **, 4 1,4 SUBR
cons obtains a new word from the f r e e storage list and places its two arguments in the address and decrement of this word, respectively. It does not check to s e e if the arguments a r e valid list structure. The value of cons i s a pointer to the word that
was just created. If the f r e e storage list has been exhausted, cons calls the garbage collector t o make a new free storage list and then performs the cons operation. SUBR predicate
The f i r s t word on the property list of an atomic symbol contains -1 o r 777778 in the address. The following subroutine depends upon this, and on the fact that NIL is located a t 0 and *T* is located at -1 and has 1 a s i t s complement pointer. ATOM SXA PDX CLA PAX TXL CLA TRA PXA AXT TRA OCT ATOMX, 4 0,4 0 ~ 4 084 *t3,4, -2 TRUE *t2
GET CAR OF ARGUMENT TRANSFER I F NOT ATOMIC I F IT IS ATOMIC
NIL IF NOT ATOMIC
ATOMX TRUE es[x;y - I
1,4 1000000 SUBR predicate
eq - is true if i t s two arguments a r e identical list structure. EQ STQ SUB TZE PXA TRA CLA TRA OCT PZE
X X *t3 0,o 184 TRUE 1s 4 1000000
TRANSFER IF EQUAL OTHERWISE VALUE IS NIL VALUE IS *T*
although they do not have t o be identical list structure in the computer. It uses eq on the atomic level and is recursive. Floating point numbers in S-expressions a r e compared for numerical equality with a floating point tolerance of 3 X loW6. Fixed point numbers a r e compared for numerical equality.
SUBR predicate equal[^;^] equal -is true if i t s arguments a r e the same S-expression,
FSUBR The value of null[x] The value of NULL TZE
list is a list of
i t s arguments. predicate
& is true
TRA CLA TRA OCT
if i t s argument is NIL which is located at 0 in the computer.
*+3 080 1,4 TRUE 1,4 1000000
The value of & is false o r true respectively. RETURN. i s a list of pairs ((ul v l ) (uz v2) tun vn)) where each u is a name and each v is a A-expression for a function. Its f i r s t argument is a list of pairs a s for define. 0r[x1. and false otherwise. After deflist has been executed with (ui vi) among its first argument. The value of 2 is true o r false respectively. the property list of ui will begin: . GO. The value of define is the list of u's.xn] : FSUBR predicate The arguments of or a r e evaluated in sequence from left to right.x2.rplaca[x. QUOTE. Its second argument i s the indicator that i s to be used. not -[x] The value of SUBR predicate not i s true if its argument is false. Interpreter and Prog Feature These a r e described elsewhere in the manual: APPLY. .y] rplacd[x.. SETQ. x. .x2. define puts an EXPR on the property list for u pointing to v. For each pair. Logical Connectives and[x . See page 41 for a description of usage. Defining Functions and Functions Useful for Property Lists define [x] EXPR pseudo-function The argument of define. PROG.. ind] EXPR pseudo-function The function deflist is a more general defining function.y] SUBR SUBR pseudo-function pseudo-function These list operators change list structure and can damage the system memory if not used properly. from left to right. . LABEL. EXPR] deflist [x. o r until the end of the list is reached. EVAL.xn] : FSUBR predicate The arguments of a r e evaluated in sequence. until one is found that is true. define[x] = deflist[x. SET. o r until the end of the list is reached. FUNCTION. until one is found that is false. . EVLIS. The function of define puts things on a t the front of the property list.
Thus it is commonly used to tack something onto the end of a property list. prop[^. however its value i s car of the r e s t of the list if the indicator is found. its name and the succeeding property a r e removed from the list. attrib[x. the old value will be replaced by the new one.y . If such an element is found. ind] : SUBR pseudo-function f The pseudo-function remprop searches the list. The two "endsn of the list a r e tied together a s indicated by the dashed line below. rempr op[x.y] -cdr[x].eq[car[x]. (EXPR (LAMBDA (X) (COND ((ATOM X) X) (T ( F F (CAR x))))))] would put EXPR followed by the LAMBDA expression for FF onto the end of the property list for FF. Otherwise the value is u[ 1. x. For example attrib[~~. T prop[cdr [x]. the second argument is the value i s cons[val.N1~]. cset[ob. csetq[ob. the value of prop i s the r e s t of the list beginning immediately after the element. When such an indicator is found.u]] - - - - SUBR get -is somewhat like prop.e] - SUBR pseudo-function The function attrib concatenates its two arguments by changing the last element of its first argument to point to the second argument. looking for all occurrences of the indicator ind. ~ = [null[x] NIL. eq[car [x].val] FEXPR pseudo-function cset csetq -is like -except that it quotes its first argument instead of evaluating it. pr~p -[x.u] SUBR functional The function prop searches the list x for an item that i s eq to y. and NIL otherwise.If deflist or define is used twice on the same object with the same indicator.^. u] = [null[x] u[ ]. ] get [ x . .val] - - - EXPR pseudo-function This pseudo-function is used to create a constant by putting the indicator APVAL and a value on the property list of an atomic symbol. where 2 is a function of no arguments. The first argument should be an atomic symbol.~.~] cadr [x]. The value of attrib is the second argument.
i. the value of sassoc is this pair. remflag[l.v. Otherwise the function u of no arguments is taken as the value of sassoc. ( ( a (a p2).. .y] = [prog[u. - - - go[~Il sassoc[x. They should & be atomic symbols. u:= cdr[u]. e. ind] EXPR pseudo-function The pseudo-function flag puts the flag ind on the property list of every atomic symbol in the list 1 Note that d cannot be an atomic symbol. The value i s a dotted pair list. There a r e two pseudo-functions for creating and removing flags respectively. It does this by patching around the indicator with a rplacd in a manner similar to the way remprop works. When an indicator appears on a property list without a property following it. which i s a list of dotted pairs.m]. . bols.y. flag -[I. No property list ever receives a duplicated flag. then it is called a flag. v:= cdr[v].car[v]].y] SUBR The function pair has a s value the list of pairs of corresponding elements of the lists x and y.u] SUBR functional The function sassoc searches y. v:= y. ind] : EXPR pseudo-function remflag removes all occurrences of the indicator ind from the property list of each atomic symbol in the list 8. Table Buildinrr and Table Reference Functions pair [x. The value of flag i s NIL. for a pair whose f i r s t element that i s x. m] u:= x. A [null[u] [null[v] r e t u r n [ m ] . The flag i s always placed immediately following the first word of the property list. The arguments x and y must be lists of the same number of elements. [null[v] . m:= cons[cons[car[u].The value of remprop is NIL.e r r o r [ ~ 3 ] ] . and must be a list of atomic sym. . An example of a flag is the indicator TRACE which informs the interpreter that the function on whose property list it appears i s to be traced. . pair[x. If such a pair i s found. ~ error[$2]]]. and the rest of the property list then follows.
(G H)] = (A (B C) D F G H). SUBR Here x is a list of pairs. append[cdr [x]. For example. append[(^ B) ( a 1 = (A B C) append [x. The value of conc i s the resulting concatenated list. k[[j].y. Note that the following M-expression is different from that given in Section I.x2. sublis[x.T cons [car [x].search[x. T .[atom[y] y. append is the resultant list.y] = [null[x] .y .y] is the result of substituting each v for the corresponding u in y. atom[z] z. append is like nconc except that nconc does not copy its first argument.car [y]].y] SUBR The value of The function append combines its two arguments into one new list.caar[j]]].y. For example.cdr [y]]]]]]] - List Handling Functions append [x.. null[y] -.y] .subst[x. k[[j].. Note that append copies the top level of the first list. ((ul v l ) (u2 v2) (un vn)) The value of sublis[x.y.xn ] - : FEXPR pseudo-function conc concatenates its arguments by stringing them all together on the top level.y. subst[x.y.subst [x. Thus it changes existing list structure and i s a pseudo-function. T . - I]] - conc[xl. . T -c cons [sublis [x..cons[subst[x.z] SUBR The function subst has a s value the result of substituting x for all occurrences of the S-expression y in the S-expression z. though the result is the same.z] = [equal[y.sublis [x. k[[j]. y .car [z]]. - - . cdar[j]]. c o n c [ ( ~(B C) D).cdr[e]]]] -- sublis [x . .y] [null[x] -.y..z] x. . equal[y. conc concatenates its arguments without copying them. (F).
nc onc -[x. e. the modified first argument. 8] SUBR predicate If the S-expression x is a member of the list 1 . A [null[u] return[v]]. [null[x] r e t ~ r n [ ~ ] ] . D))] = ((C D) B A)) reverse[t] = prog[[v]. u:=cdr[u]. (i.T. Thus reverse[(^ B (C . Otherwise. - so[AlI member[x. x). x] - - co~[cdr[xllIl reverseit] SUBR This is a function to reverse the top level of a list.y] SUBR pseudo-function The function nconc concatenates its arguments without copying the first one. v:=cons[car[u]. the value is NIL. The value of copy i s the location of the copied list. u: = t . then the value of member i s *T*. copy[x] = [null[x] ~ ~ ~ . T member[x. The operation i s identical to that of attrib except that the value is the entire result.l] = [null[l] ~. a t o m [ x. .equal[x.car[L]]-.T -. member[x. length 0.y ] = prog [[m]. - -[XI COPY SUBR This function makes a copy of the list x.cdr[l]]] - length[x] SUBR The list ( ) or NIL has The value of length is the number of items in the list x.y] has the program variable m and i s a s follows: nconc [x.v]. The program for nconc[x.cons[copy[car[x]].
The program for map[x.r e t u r n l ~ ~ ~ ] ] . f ] SUBR functional The function map is like the function maplist except that the value of map is NIL. - m:= cdr[m].f] = [null[x] NIL.car] . and map does not do a cons of the evaluated functions. etc. efface[x. then to cddr[x]. NIL). f . Arithmetic Functions These a r e discussed at length in Section IV. to x. map is used only when the action of doing f[x] is important.f ] SUBR pseudo-functional - - The function mapcon is like the function maplist except that the resultant list is a concatenated one instead of having been created by cons-ing. T cons[f [x].f - I]] map[x. and if such an element is found the function f of that element i s the value of search.-.f ] SUBR functional The function maplist is a mapping of the list x onto a new list f[x]. function plus minus type FSUBR SUBR number of args indef. maplist [x. 1 value - . equal[x. /' Functionals o r Functions with Functions a s Arguments maplis t [x.efface[x. mapcon[x. then to cdr[x].cdr ]]] These four functionals apply a function.f] = prog[[m]. the function u of one argument x is taken a s the value of search (in this case x i s .Q] - SUBR pseudo-function The function efface deletes the first appearance of the item x from the list 8 . T nconc [f [x].rplacd[k . u ] : SUBR functional The function search looks through a list x for an element that has the property p. m:= x. of course.l ] = [null[l] -.f] has the program variable m and is the following: map[x. LOOP [null[m] -. cdr.effac e[x. ~ . f . f ] = [null[x] NIL. mapcon[cdr [x]. f [m]. If there is no such element.NIL. go[~oopl1 sear~h -[ x . f]]] m a p on [x. maplist [cdr [x]. T -.
.. special[x] SUBR They a r e compiled.quotient[l. 1 2 2 2 1 1 1 1 1 1 indef.. . 2 2 2 1 1 indef.. . uns pec ial[x] SUBR pseudo-function The list x contains the names of variables that a r e no longer to be considered SPECIAL by the compiler. indef. remainder of x / ~ Xl'X2'. unc ommon[x] : SUBR pseudo-function The list x contains the names of variables that a r e no longer to be considered COMMON by the compiler. *X largest of xi smallest of xi [fixp[x]-0.XI] XY x is negative x is a number x i s a fixed point number x is a floating point no. indef.*x24. c ommon[x] SUBR pseudo-function The list x contains the names of variables that a r e to be declared COMMON. ~-. xlVx2V.difference times divide quotient remainder add 1 sub 1 max min recip expt lessp greaterp zerop onep minusp numberp f ixp float p logor logand logxor leftshift array SUBR FSUBR SUBR SUBR SUBR SUBR SUBR FSUBR FSUBR SUBR SUBR SUBR SUBR SUBR SUBR SUBR SUBR SUBR SUBR FSUBR FSUBR FSUBR SUBR SUBR predicate predicate predicate predicate predicate predicate predicate predicate 2 indef. . 2 1 n list [ x / ~remainder] . indef.Vxn ORA x1Ax2A. The Compiler and Assembler compile[x] SUBR pseudo-function The list x contains the names of previously defined functions. . pseudo-function The list x contains the names of variables that a r e to be declared SPECIAL. x 2 Y declares arrays . A xn ANA Vxn ERA x .
startread advance endread clearbuff pack unpack opchar dash digit liter error1 numob mknam . prini terpri[ SUBR pseudo-function -] terpri terminates the print line. The argument i s a list of dotted pairs. Each function to be read in consists of a list of the two arguments of 2. of -must be an atomic symbol. These a r e read in successively until a card containing NIL is encountered. punchrx] SUBR pseudo. print [x] SUBR pseudo-function The execution of print causes the S-expression x to be printed on SYSPOT and/or the on-line printer. For this reason.-function - The execution of punch causes S-expression x to be punched in BCD card images on SYSPPT. o r from the card reader. The value of print is its argument. The input follows the STOP card of the packet containing the readlap. sorting and printing functions a r e discussed in appendix F. . it should only be used to read cards that have been produced by punchlap. The character reading. The list that is read is the value of read. readlap uses remob to remove unwanted atomic symbols occurring in the listing. EXPR pseudo-function opdefine defines new symbols for the assembler LAP. each pair consisting of symbol and value. readlap[ ] EXPR pseudo-function readlap reads assembly language input and causes it to be assembled using LAP.table] opd ef ine [x] : SUBR pseudo-function The assembler LAP is discussed in appendix C. - prin l [x] SUBR pseudo-function The argument prinl -prints an atomic symbol without terminating the print line. The value of punch is its argument. Input and Output read[ -] SUBR pseudo-function The execution of read causes one list to be read from SYSPIT.lap[list.
The value of untrace is NIL.. speak. the arguments and values of these functions a r e printed each time the function is entered recursively. e r r o r s e t . 1The copied list i s the value of gens~m[ 1 SUBR I cpi. each one is guaranteed unique. FEXPR The qits in select a r e evaluated in sequence from left to right until one is found that qi = and the value of select is the value of the corresponding ei. ILL WORD I I . gensym names a r e not permanent and will not be recognized if read back in. distinct. . If no such qi is found the . functions. untrac e [x] EXPR pseudo-function This removes +he tracing from all functions in the list x. CPl -[XI SUBR cpA -copies its argument which must be a list of a very special type. Its value i s a new.T & ~ ] The function gensym has no arguments. Debugging. and E r r o r Processing trace[xl EXPR pseudo-function The argument of trace is a list of functions. After trace has been executed. value of select is that of e. Special forms cannot be traced. created atomic symbol with a print name of the form G00001. .Miscellaneous Functions prog2 [ x .Functions f o r System Control. This is illustrated in the printed output of the Wang Algorithm example.. . G00002.uncount. G99999. e r r o r . ~ ] ' SUBR It i s used mainly to perform two pseudo- The value of prog2 i s its second argument. The following pseudo-functions a r e described in the section on running the LISP system: count. This function is useful for creating atomic symbols when one i s needed. and freshly. The value of trace is NIL.
If the mode is 0. (tempus-fugit i s for MIT users only. The LISP Library The LISP Library is distributed a s the second file on the LISP setup tape. : SUBR pseudo-function dump [low. When an atomic symbol has been removed.) load[ -] : SUBR pseudo-function Program control is given to the LISP loader which expects octal correction cards. If x is *T*. To use any part of it. Pushing START will cause the program to continue. then the compiler will be overwritten with free storage. intern[x] : SUBR pseudo-function The argument of intern must be a PNAME type of structure. title] dump causes memory to be dumped in octal. plb -[ I SUBR pseudo-function This is equivalent to pushing "LOAD CARDS " on the console in the middle of a LISP program. punch out the entire library and remove the part you wish to use. returning the value NIL. The effect of excise[W'*] i s somewhat unreliable. The value of intern in either case is an atomic symbol having the specified print name. If this print name belongs to an already existing atomic symbol. otherwise a new one is created. and a transfer card. remprop [*. Be . 704 row binary cards. this is found. excise[x] : SUBR pseudo-function If x is NIL. containing zero in the prefix and tag will be dumped a s complement decrements and addresses. Executing this will cause a garbage collection to occur. This is convenient for examining list structure. The dump is from location 1 s to location . a list of full words forming a print name. It causes the symbol and all its properties to be lost unless the symbol is referred to by active list structure. It is recommended that before executing this pair.high.t empus -fugit [ ] : SUBR pseudo-function Executing this will cause a time statement to appear in the output. subsequent reading of its name from input will create a different atomic symbol. then both the compiler and LAP will be overwritten by free storage. excise may be executed more than once. pause[ 1 SUBR pseudo-function Executing this will cause a program halt. reclaim[ ] SUBR pseudo-function The value is NIL. that i s .mode. If the mode i s 1. then the dump is straight.sYM] be executed. The value is NIL. the words high. r emob[x] : SUBR This removes the atom x from the object list.
and unnecessary cards that close a define with )). each one having an EXPR or FEXPR will have its definition punched out. only the internal functions have their LAP printed. then in addition to setting the variable a. unnecessary DEFINE cards. The punched output is in a format suitable for readlap. Each of these functions must be an EXPR which has a PROG on the top level. The printout from punchlap is not a copy of the cards produced. F o r example. The process stops when a card containing the word NIL is encountered after the last function. punchlap[ 1 EXPR pseudo-function punchlap allows one to compile functions and have the results punched out in assembly language LAP.s u r e to s t r i p off comment cards. The func tions t o be compiled into LAP a r e placed at the end of the packet following the STOP card. Its argument i s a list of functions whose definitions a r e to be restored to their original condition. Each one is read individually and the result i s punched out. The PNAMEs of - - atoms in the EXPRs and FEXPRs of punchlapped functions must not contain class C characters. Each function must consist of a list of the form (name exp) which is the exact form for insertion into a define. suppose a PROG has the statement (SETQ A X). Nothing is changed by printprop. . The argument x should be a list of functions names. lap P a r t of punchlap is a dummy definition of lap. APVAL1s The following is a list of all atoms with APVALts on their property lists in the basic system and their values. EXPR pseudo-function traceset is a debugging aid. At run time. the function will print out: (A =) (U V) untraceset[x] is part of the traceset package. Some entries in the library have several parts o r define more than one function. EXPR pseudo-function pr intpr op[x] If x is an atomic symbol. No assembling into memory takes place. all of its properties will be printed in the output. traceset modifies the definition of the function s o that every SETQ on the first level inside the PROG is traced. This prevents -from being used within the memory of this packet. if this statment is executed while x has the value (U V). Nothing is changed. punchdef [x] EXPR pseudo-function If x is a list of atomic symbols.
. The entire set of objects (atomic symbols) existing in the system can be printed out by performing EVAL (OBLIST NIL).APVAL BLANK CHARCOUNT COMMA CURCHAR DOLLAR EOF EOR EQSIGN F LPAR NIL OBLIST PERIOD PLUSS RPAR SLASH STAR T *T* value (BCD blank) (character count during reading of characters) J (current character during reading of characters) $ $EOF $ $EOR$ NIL ( NIL (bucket sorted object list) 1.
The value of get is s e t aside.ar~s.a].d r ~ ~ 1 ~ [ c a eq[car [fn].args . ~~~~~]-a~~l~[caddr[fn].args. .~ ~ ~ . and the PROG feature a r e defined by using a language that follows the M-expression notation a s closely a s possible and contains some insertions in English. These M-expressions should not be taken too literally. [expr ~ ~ spread[args]. apply.a]=[ null [fn]-NIL. It shows how functional arguments bound by FUNARG a r e processed.a]]. nconc [pair[cadr[fn]. Its purpose is to describe a s closely a s possible the actual working of the interpreter and PROG feature.a]]s r~ 1.a [fn]. spread puts the individual items of this list into the AC.FSUBR] eval[cons [ fn.caddr[fn]].error ~ 2 ] ] ] ] . [fn.a ~ ~ l y [ e v a l [ f n . T-apply[cdr[sassoc [fn.cons[cons[cadr[fn]. caddr [fn]]. ~ ~ ~ ~ ~ ~ ] . Apply cannot handle special forms and will give e r r o r A2 if given one a s its f i r s t argument. spread can be regarded a s a pseudo-function of one argument. the actual program is a s t o r e and transfer where a recursion is suggested by these definitions. In many cases. args. eval.. 1 at ~rn[fn]-[~et E X P R ] . NIL] - This definition shows that evalquote is capable of handling special forms a s a sort of exception. a]]. the standard cells for transmitting arguments t o functions.APPENDIX B THE LISP INTERPRETER This appendix is written in mixed M-expressions and English. a. evcon.~[. ---- evalquote[fn. a ] . The functions evalquote. args]. and describes the way in which machine language subroutines a r e called. apply[fn. a r . LAMBDA]-eval[caddr[fn]. args]. $ARG3.args]=[get [fn. FEXPR] vget [fn. evlis.. In this description. [ ~s eq[car[fn]. This argument is a list. This is the meaning of the apparent free o r undefined variable - . MQ. The following definition'of apply is an enlargement of the one given in Section I. eq[car[fn].a.a]. ~ .
eq[car [form]. [cdr 1 atom[car[form]] -[get[car [ f o r m ] . ~ ~ ~ ~ ] . a]. evlis[cdr x ~ r . 1 atom[form]-[get[f O ~ ~ . This i s the meaning o the apparent free or undefined variable2. eval[caar[ c]. 1. a]]. get[car[form].error[A8]]]]]. A P V A L ] . a]] } evcon[c.a]] evlis[ m.a].~[. cadr eq[car [form]. - .F~u~R]-. The PROG Feature The PROG feature i s an FSUBR coded into the system. It can best be explained in English.c[apval 1. spread[evlis [cdr [form].~[[ ].error[~9]]]].a].~ a ~ ~ l ~ [ elforrn]. . FUNCTION]-~~~~[FUNARG. a]. A go-list i s formed in which each location symbol is paired with a pointer into the remainder of the program. a]=[ null[f orm]-NIL.s encountered.a]. This is then appended to the current a-list. cdr [form]]. 2.[form]. a]]] .eval[f .a. Thus each program variable is set to NIL at the entrance to the program.QUOTE]-cadr [form]. eq[car[f O~~]. a]. T-evcon[cdr [ c]. 3.a]. numberp[f orm]-f orm. As soon a s the PROG feature is entered. ~ ~ O G ] . MQ: = $ALIST: =a. the name of the variable is located on the setq i a-list. COND]-evcon[cdr[form]. a] =maplist [m. (TSx fsubr!4 ~-e~al[~0ns[cdr[sas~0~[car[form]. f The value of get i s set aside. T-apply [car [form].orm. 2 eq[car [form]. get[car[form]. In the actual system this is handled by an FSUBR rather than a s the separate special case as shown here. The remainder of the program i s searched for atomic symbols that are understood to be location symbols.~~~~]TSX subr f 4 AC: =cdr[ form]. a]].a].a. a]=[null[c]--error [A3].evlis [cdr[form].~ r o ~ [form]. although it is possible to define it by using M-expressions. the list of program variables i s used to make a new list in which each one is paired with NIL.~~~~~]-apply[fexpr !list[cdr [form]. When a set or a . get[car[form]. a]-eval[cadar [a]. ar ~~cdr[sassoc[form. 1. The value of the variable (or c s of the pair) is actually replaced with the new value.a].~ [ [ j ]eval[car[j].
Program variables follow the same rules a s h variables do. If a -i s used incorrectly or refers to a nonexistent location. its argument is evaluated and returned as the value of the most recent prog that has been entered. If a prog runs out of statements. with the exception of the special forms cond. See Appendix D for an explanation of variable declaration. This form may also occur a s one of the value parts of a conditional expression. & a s distinct from setq can only be used to set common variables. 7. it differs from other conds in the following ways. When a statement is executed. If the current binding of the variable is at a higher level than the entrance to the prog. When the form cond occurs on the top level of a prog. The form go may be used only in two ways. its value is NIL. If a variable is purely local. only the first or most recent occurrence i s changed. b. this has the following meaning. it need not be declared. The statement 5 is executed by performing eval[s. When a -is compiled. go. prog although the method of execution is much different. c. 1. a. a. .If the variable i s bound several times on the a-list. e r r o r diagnostic A6 go will occur. e r r o r diagnostic A3 will not occur.a]. where 2 i s the current a-list. if this conditional expression occurs on the top level of the prog. 8. for example. all of which a r e peculiar to prog. b. 2. b. They may be set a t a lower level than that at which they a r e bound. Special variables can be used a s free variables in compiled functions. Instead. 5 . the prog will c6ntinue with the next statement. return. then e r r o r diagnostic A4 o r A5 will occur. it will have the same effect a s when it is interpreted. 1. a go is always corn1 piled a s a transfer. (GO X) may occur on the top level of the prog. x must be a location symbol of this prog and not another one on a higher or lower level. then the change will remain in effect throughout the scope of that binding. The following points should be noted concerning declared variables. and then ignoring the value. and the old value will be lost. When a return is encountered at any point. If the variable does not occur on the a-list. a. If the cond runs out of clauses. 4. Common program variables maintain complete communication between compiled programs and the interpreter. 6. It is the only instance in which a g o c a n occur inside a cond. setq and the pseudo-functionset.
If the origin is an atomic symbol other than NIL. type is usually either SUBR o r FSUBR. The f i r s t argument i s the listing. -does not produce binary output in the form of cards. Its input is in the form of an S-expression that remains in core memory during the entire assembly. Origin The origin informs the assembler where the assembly is to start. - Format lap is a pseudo-function with two arguments. then the cell specifying the f i r s t unused location in binary program space is updated. o r instructions if they a r e composite S-expressions o r if they a r e NIL. is placed on the property list of the atomic symbol name. The f i r s t item of the listing is always the origin. The value of lap is the final symbol table. but it can also be used for defining functions in machine language. Following the indicator is a pointer to a word containing TXL. n is the number of arguments which the subroutine expects. then the assembly s t a r t s at that locat ion. then the assembly i s in binary prog r a m space a s in the case above. When the assembly is completed.APPENDIX C THE LISP ASSEMBLY PROGRAM (LAP) lap is a two-pass assembler. then the assembly will s t a r t in the f i r s t available location in binary program space. The value of this SYM is a number specifying the starting location. - Svmbols Atomic symbols appearing on the listing (except NIL o r the f i r s t item on the listing) . lap is an entirely internal assembler. 4. The origin must have one of the following formats. the second argument is the initial symbol table. No input tape is moved during the assembly. the indicator. If the origin is an octal o r decimal number. then this symbol must have a permanent value (SYM) on its property list. and whether it is to be made available a s a LISP function. All remaining items of the listing a r e either location symbols if they a r e atomic symbols other than NIL. an e r r o r diagnostic will be given. and for making patches. If the assembly cannot fit in binary program space. If the origin is NIL. It was specifically designed for use by the new compiler. If the origin is of the f o r m (name type n). If the assembly is successfully completed. 3. and the number n in the decrement. 1. type. 2. the f i r s t location of the program just assembled in the address. It assembles lap directly into memory during the second pass.
If the field is a number. 3. The symbol table i s searched for an atomic symbol that i s identical to the field. then a literal quantity containing a in the decrement is created. The appearance of the symbol defines it a s the location of the next instruction in the listing. a SUBR. The expression a is protected s o that it can never * be collected by the garbage collector..a r e treated a s location symbols. An arithmetic -1 is reduced to 77777Q. It is the address of this quantity that is assembled. 2 If the field is of the form (E a ). Permanent symbols a r e defined by putting the indicator SYM followed by a pointer to a value on their property lists. Symbols occurring on this table a r e defined only for the current assembly. Quoted S-expressions a r e protected against being collected by the garbage collector. however. The atomic symbol NIL has f o r its value the contents of the cell $ORG. e. a. the fields a r e combined a s follows. the address of the S-expression a . and then OR1ed into the word. During an assembly that is not in binary program space. During pass one. Instructions Each instruction is a list of from zero to four fields. The atomic symbol has the current location a s its value. It is also the value of lap. If the field is atomic. The fourth field is reduced modulo 215 and is OR1ed into the decrement. 2. b. or an FSUBR. 4. and appended to the initial symbol table to form the final symbol table. 1. The property list of the atomic field i s searched for either a SYM. A new literal will not be created if it is equal to one that already exists. 1. d. Each field i s evaluated in the same manner. This is used in pass two to evaluate the symbols when they occur in instructions. these symbols and their values a r e made into a pair list. 3. If the field is of the form (SPECIAL x). If one does not already exist. Fields Fields a r e evaluated by testing for each of the following conditions in the order listed. then the value is the address of the SPECIAL cell on the property list of x. A tag of four is written "4". . The first field is taken a s a full word. then its numerical value i s used. this cell contains the starting address of the next assembly to go into binary program space. then the value of the field is the complement of . If the field is of the form (QUOTE a ). The symbol table is discarded after each assembly. c. 4. The third field is shifted left 15 bits. it will be created. The second field is reduced algebraically modulo 2 15. A tag of 2 in an instruction with indirect bits i s written "602Qt1. and is OR1ed into the address part of the word.
2* * Opdef ine opdefine is a pseudo-function f o r defining new quantities for LAP.The SPECIAL cell itself (but not the entire atom) is protected against garbage collection. LAP ( (6217Q (TRA NIL) )NIL) LAP ( (NIL (CLA A) (TSX 6204Q) (TRA B) ) ( (A 6243Q) (B 6220Q) ) ) . Note that these pairs a r e not "dotted pairs. E r r o r Diagnostics *L *L *L *L 1* Unable to determine origin. Assembly incomplete. and their sum is taken. Example (CLA 500Q8) (TRA 2Q9) (LOAD 1000) (OVBGN 7432Q) ) ) The following op-codes a r e defined in the standard system: AXT PXA SUB PXD CLA SXA STD SXD LDQ LXA ST0 TIX LXD STQ Trn PAX STR TNX PDX STZ TNZ Examples of the Use of LAP Example 1: A LISP function The predicate greater induces an arbitrary canonical order among atomic symbols. Out of binary program space. the field is assumed to be a list of subfields. The subfields must be of types 1 4 above. No assembly. Second pass cancelled. 62 17Q contains C I A 6243Q and this instruction must be moved to the patch. LAP ( ( (GREATER SUBR 2) (TI& (* 3)) (PXA 0 0) (TRA 1 4) (CLA (QUOTE *T* ) ) (TRA 1 4) )NIL) Example 2: A patch OPDEFINE ( ( TRA TSX TXH TXI TXL TZE XCA The instruction TSX 6204Q must be inserted after location 62 17Q. Assembly incomplete. In all other cases. 3 Undefined symbol. Its argument is a list of pairs. 5. Each pair is a symbol and its numerical value. 4* Type five field contains type five fields inside itself. It puts a SYM on the property list of the symbol that is being defined.
binary program space. 4. taking only from 50 per cent to 80 per cent a s much space.APPENDIX D THE LISP COMPILER The LISP Compiler i s a program written in LISP that translates S-expression definitions of functions into machine language subroutines. LAP. To avoid having to repeat the slow bootstrapping operation each time a system tape is created. the S-expression f o r the function is translated into assembly language. When the compiler is called upon to compile a function. 3. one gains a s free storage the total space formerly occupied by the S-expression definition. The compiler was written and debugged a s a LISP program consisting of a set of S-expression definitions of functions. LAP then proceeds to assemble this program into binary program space. The compiler was commanded to compile itself. Any future change or correction to the compiler must start with these definitions. It is an optional feature that makes programs run many times faster than they would if they were to be interpreted at run time by the interpreter. . therefore they a r e included in the LISP Library. Compiled programs a r e also more economical with memory than their corresponding S-expressions. the entire compiler was punched out in assembly language by using punchlap. First. Thus an EXPR. Experience has shown that compiled programs run anywhere from 10 to 100 times a s fast a s interpreted programs. Second. The compiler is called by using the pseudo-function compile. The processing of each function occurs in three steps. o r an FEXPR. the compiler in assembly language i s read in by using readlap. The only reasons why the compiler is regarded a s a pseudo-function a r e that it calls LAP. The compiler has an interesting and perhaps unique history. the assembly 1 - 1. When a system tape is to be made. then the compiler will print this fact and proceed with the next function. 2. which i s normally Since the compiled program is not otherwise accessible. If no S-expression is found. since most parts of the compiler a r e being interpreted during most of this time. has been changed to a SUBR or an FSUBR. the time depending upon the nature of the program. It takes more than 5 minutes on the IBM 7090 computer to do this. it looks for an EXPR or FEXPR on the property list of the function name.' The major part of the compiler is a translator or function from the S-expression function notation into the assembly language. This operation is called boot strapping. It was developed in the following steps: 1. Each atomic symbol on this list should have either an EXPR o r an FEXPR on its property list before being compiled. respectively. The argument of compile -is a list of the names of functions to be compiled. and it removes EXPRts and FEXPR1s when it has finished compiling. The compiler then translates this S-expression into an S-expression that represents a subroutine in the LISP Assembly Language (LAP).
Example (LAMBDA (A) (PROG (B) S (SETQ B A) (COND ((NULL B) (RETURN C))) (SETQ C (CONS (CAR A) C)) (GO S) )) A and B a r e bound variables. If excise [NIL] i s executed. the compiler will print a diagnostic and continue. When certain e r r o r s caused by undeclared free variables occur. and compile them only when they a r e known to work. They must be defined before any function that calls them is compiled. When writing a large LISP program. If excise [*T*] is executed. it must have been bound by a higher level function. Any variable that i s not bound is free. F r e e Variables A variable is bound in a particular function when it occurs in a list of bound variables following the word LAMBDA o r PROG. If a program is being run interpretively. then the compiler will be removed. Persons planning to use the compiler should note the following points: 1. This is discussed at length in this appendix. This diagnostic will be spuriously produced when programs leaning on APVALs a r e compiled. Compiled functions that use interpreted functions will call the interpreter to evaluate these at run time. C is a free variable. Finally. (Special forms a r e an exception to this rule. the resulting function will not compile properly. e r r o r diagnostic *A 89 will occur. When a portion of the system is excised. One may execute excise [NIL] and then excise [*T*] at a later time. The interpreter is designed to link with compiled functions. The order in which functions a r e compiled is of no significance. then the EXPR o r FEXPR is removed from the property list. the region of memory that it occupied is converted into additional free-storage space. When a variable is used free. It is not necessary to compile all of the functions that a r e used in a particular run. then the compiler and LAP will both be excised. it is better to debug the individual function definitions by using the interpreter. 2. It is not even necessary to have all of the functions defined until they a r e actually used at run time. ) 3. Excise The compiler and the assembler LAP can be removed from the system by using the pseudo-function excise. and a free variable i s used without having been bound on a higher level. if no e r r o r has occurred. If the form LABEL is used dynamically. F r e e variables in compiled functions must be declared before the function is compiled. 4.language program is assembled by LAP. .
The declaration can be removed by uncommon[a]. the old value must be restored.If the program is being run compiled. free variable. and the variable may have value NIL. then the quantity in the SPECIAL cell is picked up. where a i s a list of variable names. the old value is saved on the push-down list. SPECIAL variables have the indicator SPECIAL on their property lists Following the indicator there is a pointer to a fixed cell. The compiler refers to SPECIAL cells. They do not increase run time significantly. When it is no longer bound. SPECIAL variables. where a is a list of variable names. However. they do provide complete communication between interpreted and compiled functions. When this variable is bound. a new cell i s created and i s actually a different variable. Other functions cannot find this private cell. When they is given this a-list. and i s not needed at run time. COMMON variables have the flag COMMON on their property lists. It is important that the declaration be in effect at compile time. This sets up the SPECIAL indicator and creates a SPECIAL cell. SPECIAL variables a r e inexpensive and will allow free communication among compiled functions. SPECIAL variables a r e declared by using the pseudo-function special[a]. removed. a r e to be evaluated. . Functional Constants Consider the following definition of a function dot by using an S-expression: (YDOT (LAMBDA (X Y) (MAPLIST X (FUNCTION (LAMBDA (J) (CONS (CAR J) Y)) )))) . This happens at run time. this is only used to inform the compiler that they a r e COMMON. Both the indicator and the cell can be removed by the pseudo-function unspecial[a]. When a function uses this variable free. the diagnostic may not occur. Any variable that is not declared will be considered an ordinary variable. making it impossible to use it a s a. COMMON variables a r e declared by common[a]. where a i s a list of variable names. It may be removed at run time. SPECIAL and COMMON variables must be declared before compiling. however. and then declared again. When functions a r e translated into subroutines. the concept of a variable is translated into a location where an argument is stored. COMMON variables a r e bound on an a-list by the compiled functions. If the variable i s an ordinary one. SPECIAL variables cannot be communicated between the interpreter and compiled functions. There a r e three types of variables in compiled functions: ordinary variables. The use of COMMON variables will slow down any compiled function using them. using the LAP field (SPECIAL X) whose value i s the address of the SPECIAL cell. and COMMON variables. then a storage location for it is set up on the push-down list. When a variable has been declared. and the current value is stored in the SPECLAL cell. where a is a list of variable names.
it is evident that it contains a bound variable "Jtt. Once a direct TSX link is made. then link will . and the number of arguments that a r e being transmitted. 2. If we consider it a s a separate function.4. If there is a subroutine available. Tracing Compiled Functions subject to the following restrictions. The trace must be declared after the function has been compiled. even though it i s bound in YDOT. the first time any call i s executed. MQj $ARG3. Functional Arguments MAPLIST can be defined in S-expressions a s follows: (MAPLIST (LAMBDA (L FN) (COND ((NULL L) NIL) (T (CONS (FN L) (MAPLIST (CDR L) FN))) ))) The variable FN is used to bind a functional argument.. this particular calling point will not be traced. then link will call the interpreter that may find an EXPR o r FEXPR. The normal procedure for calling a compiled function is to place the arguments in the AC. However. The address and the decrement of the STR specify the name of the function that is being called.Following the word FUNCTION is a functional constant. Link Link is the routine that creates all linkage of compiled functions at run time. This free variable must be declared SPECIAL o r COMMON. This type of variable must be declared COMMON. (Link will not make a TSX a s long a s the called function i s being traced.. the value of FN is a function definition. respectively. trace -will work for compiled functions. . ) 1. form the instruction TSX and plant this on top of the STR. The tag contains a 7. and a free variable "Yfl. That is. If there i s no SUBR or FSUBR for the function that is being called. and then to TSX FN. there will be an STR in place of the TSX.
Overlord reads cards from the input looking for Overlord direction cards. address data word . followed by a very long record that fills up almost all of the core memory of the machine. the reading and writing of entire core images. Before any packet is read. the entire system is read out onto SYSTMP. and in fact i s a copy of it. Control then goes to a loader that reads octal correction cards until it recognizes the second loader card which i s a binary transfer card to Overlord. The LISP System uses 5 tape drives. It controls the handling of tapes. They a r e listed here by name together with their customary addresses. In the latter case. Either a complete core image is read from SYSTMP. Octal corrections may be placed between the two cards of this loader. and the taking of dumps. After each packet. one of two things may happen. SYSTAP SYSTMP SYSPIT SYSPOT SYSPPT Contains the System Receives the Core Image Punched Card Input Printed Output Punched Card Output B7 B3 A2 A3 A4 The system tape contains a small bootstrap record with a loader.THE MONITOR Overlord is the monitor of the LISP System. all function definitions and other memory changes a r e preserved. The system is called by the two-card LISP loader which is placed in the on-line card reader. The format of these will be specified later. Card Format Octal correction cards can alter up to 4 words of memory per card. the historical memory of the system. Overlord cards either instruct the monitor to perform some specific function or else signal that a packet of doublets for evaluation is to follow immediately.APPENDIX E OVERLORD . or the state of memory at the finish of the packet is read out onto SYSTMP. The card columns to use a r e a s follows. The first loader card causes SYSTAP to be selected and the entire memory i s immediately filled. and thus memory is restored to the condition it was in before the packet was read. It is written in the same format a s SYSTAP. Each change specifies an address (5 octal digits) and a word to be placed there (12 octal digits). Other cards a r e ignored except for the first one which i s printed in the output.
If the FIN card came from SYSPIT. The system uses five tapes designated by the names SYSTAP.Overlord c a r d s have the Overlord direction beginning in column 8. If the FIN card was read on-line. The comments may begin after the f i r s t blank past column 16. Otherwise. and free storage in that order. N1. SETSET The SETSET card is like SET except that it s e t s even if there has been an e r r o r . The f i r s t two fields a r e octal o r decimal integers specifying the range of the dump. An end of file is written on SYSPPT only if it has been used. N3. TEST Specifies that a packet i s to follow and that memory i s to be restored from SYSTMP after the packet has been evaluated. DUMP Ll. N2. The fields a r e octal o r decimal integers. SYSPIT. TST Same a s TEST SET The SET card specifies that a packet is t o follow and that the memory state following the evaluation of the packet is to be s e t onto SYSTMP.0 This Overlord card causes an octal dump of memory to be printed. then . Overlord Cards TAPE SYSPPT. making it impossible to do any further reading (except of numbers). SYSTMP. 1 mode specifies that if the prefix and tag a r e a s of a word a r e zero. The third field specifies the mode. N4 SIZE The size card specifies the amount of storage to be allocated to binary program space.L2. If the card has no other field. This makes a considerable amount of f r e e storage available but may cause trouble if certain atoms that a r e needed a r e not protected in some manner. push-down. B4 The TAPE Overlord card defines the actual drives to be assigned to the tapes. and SYSPPT. If an e r r o r occurs during the evaluation of the packet. the computer halts after doing these things. The SIZE card must be used only once at the time when the system is created from a binary card deck. then the memory is to be restored from SYSTMP instead. then comments may begin in column 16. FIN Causes the computer t o halt. The actual tape units may range from A0 through C9. the other fields of the card begin in column 16 and a r e separated by commas. 0 mode specifies a straight dump. SYSPOT. An end of file mark is written on SYSPOT. full words. DEBUG This direction is like TEST except that after the doublets have been read in the entire object list is thrown away. then the complements of the address and decrement a r e dumped instead.
Down-Input comes from the card reader.SYSPIT is advanced past the next end of file mark before the halt occurs. push RESET then START. Use of Sense Switches Up-Input comes from SYSPIT. The loader cards and octal correction cards always go on-line. Down-The instruction STR will cause control to go to Overlord immediately. It may be mounted on the SYSTAP drive for some future run to use definitions that have been set onto it. 5 Up-No effect Down-Suppresses output normally written on SYSPOT and SYSPPT.7 with all bits of AC and MQ filled with ones. To return control to Overlord from this condition. After a LISP run. 6 Up-The instruction STR will cause the interpreter to give e r r o r diagnostic F 5 and continue with the next doublet. 3 Up-No effect Down-All output that is written onto either SYSPOT o r SYSPPT will also appear on the on-line printer. the reel of tape that has been mounted on the SYSTMP drive has become a system tape containing the basic system plus any changes that have been set onto it. 1 The normal terminating condition of a LISP run is an HPR 77777. These switches a r e interrogated at the beginning of each record. .
the 48 BCD characters a r e divided into the following categories. b. The first two characters must not be $ $. Symbols beginning with a Class B character a r e interpreted a s numbers.. An atomic symbol. All atomic symbols except numbers and gensyms a r e on a list called the object list. Input is always from either SYSPIT o r the card reader. The atomic symbols a r e thrown into buckets by a hash process on their names. F o r the purpose of giving a more extended definition of an atomic symbol than was given in Section I. Z = * / 0 1 2 3 4 5 6 7 8 9 t . a new atomic symbol with its property list i s created. Punched output is always on SYSPPT and/or the on-line printer. (blank) Class D $ Class E (4-8 punch) The 4-8 punch should not be used. The comma and blank a r e completely equivalent. - . The read and write programs allow one to read and write S-expressions. to process them internally.. Printed output is always written on SYSPOT and/or the on-line printer. . If it has not been encountered previously.( l l punch) ClassB Class C ( ) . This speeds up the search that must occur during reading. to break atomic symbols into their constituent characters. LISP READ PRINT and PUNCH The LISP read program reads S-expressions in the form of BCD characters and and translates them into list structures. and to form atomic symbols from individual characters. An ordinary atomic symbol is a sequence of up to 30 characters from classes A. and the character read and write. There is a provision for reading in atomic symbols containing arbitrary characters. It recognizes the delimiters ll(lland'l)ll the separators . It. The actual input/output routines a r e identical for both the LISP read and write. This list is made of sublists called buckets. and (blank). ClassA ABC. c. It must be delimited on either side by a character from class C. B. a.APPENDIX F LISP INPUT AND OUTPUT This appendix describes the LISP read and write programs and the charactermanipulation programs. The first character must not be from class B. The manner in which these choices a r e controlled was described in Appendix E. Some sort of number conversion is attempted even if it does not make sense. is compared with existing atomic symbols. when read in. The character-manipulating programs allow one to read and write individual characters. and Dj with the following restrictions.
Only the string s is used in forming the print name of the atomic symbol. and d is any character not contained in the string s. respectively. reading will continue into the next S-expression. and does not terminate the print line (unless it is full). These must be handled with some care because if a digit i s considered a s an ordinary integer ' . IJV* ) The operation of the read program i s critically dependent upon the parsing of left and right parentheses. Characters and Character Objects Each of the sixty-four 6-bit binary numbers corresponds to a BCD character. card boundaries a r e ignored. will terminate reading and cause an e r r o r diagnostic. In this case. If an S-expression i s deficient in one o r more right parentheses. Of the 64 characters. When a LISP function is described which has a character as either value or argument. The second group of legal characters consists of the digits from 0 to 9. the print or punch buffer i s written out and cleared s o that the next section of output begins on a new record. d and the dollar signs will not appear when the atomic symbol is printed out. The pseudo-functions print and punch write one S-expression on the printed o r pwched output. respectively. if we include illegal characters. An unmatched right parenthesis. and then clears it. The read program is called at the beginning of each packet to read doublets for evalquote until it comes to the S-expression STOP. After this. The print names of the remaining characters will be described later. it will begin reading with the card following the STOP card because the read buffer i s cleared by evalquote after the doublets and STOP have been read. which must be an atomic symbol. and the key-punch character i s simply that character. in order to manipulate these characters via LISP functions. and one S-expression i s read each time read is called. The f i r s t group of legal characters consists of the letters of the alphabet from A to Z . without ambiguity. In each case. Therefore.)- will print a s A 1)) $$/-*I -. terpri prints what is left in the print buffer. read has no arguments. Each letter i s a legitimate atomic symbol. and therefore may be referred to in a straightforward way.This i s done by punching the form $$dsd. where s i s any string of up to 30 characters. Its value is the S-expression that it reads. o r a dot that i s out of context. each of them has a corresponding object. prinl is a pseudo-function that prints its argument. read may also be used explicitly by the programmer. we really mean that it has an object corresponding to a character a s value or argument. 48 correspond to characters on the key punch. Examples Input $ $XAX $ $O))( $ $-w.
there is a set of special character-value objects which can be used to refer to them. The third group of legal characters is the special characters. and this object will not be the same a s the character object for the same digit. ) i . A typical special character -value object.rather than a character a new nonunique object will be created corresponding to it.(11 punch) * blank - The following examples illustrate the use of their objects and their raison d a t r e . Each example consists of a doublet for evalquote followed by the result. has the following structure ". and If. Examples EVAL (DOLLAR NIL) value i s " $ EVAL ((PRINT PERIOD) NIL) value i s ". it will not point to the corresponding character object. -1 PNAME I I APVAL I Thus "DOLLAR has value " $ The special character value objects and their permanent values are: DOLLAR SLASH LPAR RPAR COMMA PERIOD PLUSS DASH STAR BLANK EQSIGN ". even though the result of an arithmetic operation lies between 0 and 9. this will lead to error. say DOLLAR. Thus character objects for 0 through 9 may be obtained only by reading them or by manipulation of print names. even though it has the same print name. is also printed. such a s $ and "= characters a r e not legitimate atomic symbols. These correspond Since some of these to the remaining characters on the key punch. These may be used in arithmetic just a s any other number but. Since the character-handling programs depend on the character objects being in specific locations. . The read program has been arranged so that digits 0 through 9 read in a s the corresponding character objects.
The character-packing functions are: 1. The end-of-file character has print name $EOF$ and the endof-record character has print name $EOR $. Thus it is possible to go from a character to the c o r r e sponding object o r conversely by a single addition o r subtraction. pack [c] : SUBR pseudo-function The argument of packmust be a character object. The maximum length of the sequence is 120 characters. Each operation on BOFFO either adds another character at the end of the sequence o r c l e a r s BOFFO. whose values a r e $EOR $ and $EOF$ respectively. the to their octal ~ e p r e s e n t a t i o n s character 77 corresponds t o a character object with print name $IL77$. The last word is filled out with the illegal character code 77 if necessary. mknam [ ] SUBR pseudo -function mknam is a function of no arguments. Its value is a list of full words containing the characters in BOFFO in packed BCD form. BOFFO is used t o s t o r e the characters until they a r e to be combined.The remaining characters a r e all illegal a s far a s the key punch is concerned. because it isn't necessary to search property l i s t s of character objects for their print names. The value of pack is NIL. s e t s BOFFO t o the null sequence. This speeds up character-handling considerably. e. (Positive decimal integers from 0 to 9 a r e converted s o a s to point to the corresponding character object. 4. Its value is the numerical object represented by the sequence of characters in BOFFO. After mknam is performed. Note that intern [mknam[ ]I yields the object whose print name is in BOFFO. It c l e a r s BOFFO and has value NIL. the names may be deduced from the object locations. respectively. but the character-packing functions a r e described in t e r m s of their effects on BOFFO. The character objects a r e arranged in the machine s o that their first cells occupy successive storage locations. clearbuff [ ] SUBR pseudo -func tion clearbuff is a function of no arguments. an attempt to add more characters will cause an e r r o r . corresponding to these character objects a r e two character value objects EOR and EOF.. Packing and Unpacking Characters When a sequence of characters is t o be made into either a print name o r a numerical object. The r e s t of the illegal character objects have print names corresponding preceded by $IL and followed by $. the characters must be put one by one into a buffer called BOFFO. F o r instance. The two characters corresponding to 12 and 72 have been reserved for end-of-file and endof-record. BOFFO is automatically cleared. BOFFO contains a sequence of characters. The contents of BOFFO a r e undefined until a clearbuff has been performed. 3. It is not available explicitly to the LISP programmer. i. 2. numob [ ] ' SUBR pseudo -function numob is a function of no arguments. pack adds the character c at the end of the sequence of characters in BOFFO. ) - - - . At any point.
Its value is T if the character is a letter of the alphabet. i. SUBR predicate 4. The value of startread is the first character on that card. digit [c]: digit has a s argument a character object. If it does not already exist. There a r e three functions which affect the value of CURCHAR: 1. unpack considers the full word to be a set of 6 BCD characters.. Its value is T if the character is t. and F otherwise. and F otherwise. opchar treats both minus signs equivalently. /. 6. liter [c]: SUBR predicate liter has a s argument a character object. the column number of the character given by CURCHAR. Its value i s T if the character is a digit between 0 and 9. There is also an object CHARCOUNT whose value i s an integer object giving the column just read on the card. 1: . and F otherwise. 3. opchar [c]: SUBR predicate opchar has a s argument a character object. or =. -. e. The Character -Reading Functions The character-reading functions make it possible to read characters one by one from input. then a new atomic symbol will be created. startread [ : SUBR ps eudo-function startread is a function of no arguments which causes a new card to be read. - - - *. unpack [x]: SUBR pseudo-function This function has a s argument a pointer to a full word. The Character-Classifying Predicates 1. h ~ t e r n [ ~ n a m e ] : SUBR pseudo-function This function has a s argument a pointer to a PNAME type structure such a s - Its value is the atomic symbol having this print name. SUBR predicate 2. There is an object CURCHAR whose value is the character most recently read (as an object). dash [c]: dash -has a s argument a character object. or more precisely.5. Its value i s T if the character is either an 11-punch minus or an 8 4 punch minus. and has a s value a list of these char act e r s ignoring all characters including and following the first 77. and F otherwise.
the entire card i s printed out along with a visual pointer to the defective character. e. A startread may be performed before the current card has been completely read. Both CURCHAR and CHARCOUNT a r e undefined until a startread is performed. either by successive advances o r by an endread. v .the object corresponding to the first character on the card. An advance following endread acts like a startread. After reading $EOR$. The new value of CURCHAR is the same a s the output of advance. If e r r o r 1 i s performed before the first startread o r while CURCHAR has value $EOR $ o r $EOF $. have value $EOR $. the A will not appear. executing advance also increases the value of CHARCOUNT by 1. advance [ 1: SUBR pseudo -function advance is a function of no arguments which causes the next character to be read. 3. the next advance will act like a startread. However. If CURCHAR already has value $EOR $ and endread is performed.. the next advance will have value $EOR$. 1: Diagnostic Function SUBR pseudo-function e r r o r 1 [ 1: errorL is a function of no arguments and has value NIL. CHARCOUNT is undefined when CURCHAR is either $EOR $ or $EOF $. it will have no effect. Any number of characters in a given line may be marked by e r r o r 1 . It should be executed only while reading characters from a card (or tape). After the 72nd character on the card has been read. the value of startread i s $EOF$. Its effect i s to mark the character just read. endread sets CURCHAR to $EOR$ and leaves CHARCOUNT undefined. If an end-of-file condition exists. Executing a startread before the current card has been completed will cause the e r r o r 1 printout to be lost. Successive endreads will cause the e r r o r l printout to be reprinted. a pointer to C would look like this: ABCDEFG A If e r r o r 1 is performed an even number of times on the same character.. The value of advance is that character. and the value of CHARCOUNT becomes 1. the value of endread i s always $EOR $. will read the first character of the next card unless an end-of-file condition exists. s o that when the end of the card i s reached. i. a s usual. i. 2. endread [ SUBR pseudo-function endread i s a function of no arguments which causes the remainder of the card to be read and ignored. e. For a line consisting of ABCDEFG followed by blanks. The value of CURCHAR becomes the same a s the output of startread. CURCHAR will remain the same and endread will. CURCHAR. The card is considered to have been completed when CURCHAR has been set to $EOR$.
The available space i s divided among binary program space. I/O. Full-word space is filled with the BCD characters of PNAMEts. Loader LAP Compiler Free Storage Full Words Push-Down List Binary Program Space Interpreter. push-down list. evalquote doublets waiting to be executed. and partial results of the computation that is in progress. Free storage is the area in the computer where list structures are stored. This part of the memory is then converted into free storage. This f includes the property lists of atomic symbols. APVALts. Overlord. and other system coding The addresses in this chart a r e only approximate. Garbage Collector. and free-storage space a s specified on the SIZE card when the system i s made. When the compiler and LAP a r e not to be used again. the actual numbers . they may be eliminated by executing the pseudo-function excise. Arithmetic. Read Print.APPENDIX G MEMORY ALLOCATION AND THE GARBAGE COLLECTOR The following diagram shows the way in which space i s allocated in the LISP System. the definitions o all EXPRts and FEXPR1s. full-word space.
the garbage collector is called automatically. Full-word space is handled in the same way. the new available word lists are made by stringing all unmarked words together. In full-word space. there are many words in free storage and full-word space that are no longer needed. the signs in free storage a r e set plus. When either of these lists is exhausted in the middle of a computation. This protects partial results of the computation that is in progress. After the marking is done. the garbage collector starts marking from several base positions including the following: 1. Marking is done in a bit table which is next to full-word space. and the free-storage list is set the to & of what it formerly was. Marking proceeds as follows. which is a list of registers scattered throughout the memory where binary programs store list structures that must be protected. No use i s made of consecutive storage in either of these areas of memory. The temlis. All available words in the free-storage area that are not in use a r e strung together in one long list called the free-storage list. Any trap that prevents completion of a garbage collection will create a panic condition in memory from which there is no recovery. and c a r and & of the cell a r e marked. 2. In free storage. If the cell is in full-word space. then the sign is set minus. and the TXL words of SUBRtsBFSUBRts. The portion of the push-down list that is currently being used. then nothing is done. Unless the computation i s too large for the system. If the cell i s anywhere else. If the cell is in free storage. ' . It can be recognized by the stationary pattern of the MQ lights. This protects the atomic symbols. Finally. The object list that includes all atomic symbols except numbers and generated names. Every time a word is needed (for example. Since it is important that all needed lists be marked. there i s no room in the word itself. They are both scrambled. by s) first word on the free-storage list is used. 3. and all S-expressions that hang on the property lists of atomic symbols.of numerical atomic structures. the sign bit i s used for marking. then the bit table is marked. and SYMts. The garbage collector locates these by marking those words that are needed. A garbage collection takes approximately 1 second on the IBM 7090 computer.
All saving of temporary results in LISP is performed on a linear block of storage called the push-down list. A recursive definition always has the possibility of not terminating and of being infinitely regressive. and that they be later restored. This is done autorrlatically and need not be programmed explicitly. Since it is in the nature of recursion that the first block to be saved i s always the last block to be restored. The decrement of this cell contains the complementary address of the first available unused location on the push-down list. Its power lies in its ability to define an algorithm in terms of itself. Each block contains parameters that tell UNSAVE how many words a r e to be moved. This requires that all temporary stored results related to the computation that is in progress be set aside when a piece of coding is to be used recursively. those put there by SAVE. Some recursive definitions may terminate when given certain inputs and not terminate for others. A definition of this type is called recursive. Because pointers to list structures a r e normally stored on the push-down list. in these last cases it must be restored upon leaving these routines. and those put there by *MOVE. it is often possible to show that particular cases will o r will not terminate. *MOVE i s used to update CPPI and index register 1. it is possible to keep the push-down list compact. however. It is theoretically impossible to determine whether a definition will terminate in the general case. LISP is designed in such a way that all functions for which the possibility of recursion can exist a r e in fact recursive. This may come about either directly by using the name of the function. except during certain nonrecursive subroutines. to place the arguments on the push-down list. Each set of stored data that i s moved onto the push-down list is in a block labeled with its size and the name of the subroutine from which it came. All data a r e stored directly on the push-down list and referenced by using index register 1. and where they a r e to be moved to. the . SAVE blocks a r e moved from fixed locations in certain subroutines onto the push-down list. and to set up the parameters f o r the push-down block. and then moved back to the place where they came from by UNSAVE. There a r e two types of blocks to be found on the push-down list. Functions compiled by the LISP compiler do not make use of storage cells located near the actual programming.APPENDIX H RECURSION AND THE PUSH-DOWN LIST One of the most powerful resources of the LISP language i s its ability to accept function definitions that make use of the very function that is being defined. Index register 1 also contains this quantity. o r indirectly through a chain of function definitions that eventually return to the original ones. The frontier of the push-down list can always be found by referring to the cell CPPI.
and is normally printed out after e r r o r diagnostics. it is possible to form a list of these names. the sign bit must be negative. In this case. .garbage collector must m a r k the currently active portion of the push-down list during a garbage collection. Sometimes quantities a r e placed on the push. When an e r r o r occurs. Cells on the active portion of the push-down list having a negative sign bit will not be marked. an examination of the push-down list is an excellent indication of what was occurring at the time of the e r r o r . This is called the backtrace. Since each block on the push-down list has the name of the function to which it belongs.down list which should not be marked.
is more suitable to the "age of automationu than the quote from Lewis Carroll. however. SHARE LISP differs somewhat from the LISP 1. the f i r s t time is the age of the packet by definition. when evalquote is left. it is felt. simply printed out a "FLAP TRAPtt e r r o r m e s sage and went on to the next pair of S-expressions to be evaluated. When this t r a p occ u r s and the offending exponent is negative. this is zero when evalquote is f i r s t entered and the second time is the age of the system being used. concise. The new system s t o r e s a floating -point zero in the accumulator when an underflow occurs. The old system. Thus. impersonal manner which. requires the computer to have a millisecond clock in cell 5 (RPQ F 89349. Flap T r a p Every now and then a state of affairs known a s floating-point t r a p occurs this r e sults when a floating-point arithmetic instruction generates a number whose exponent is too large in magnitude for the eight-bit field reserved for it. In fact. thus.) Time The new system prints the time upon entering and leaving evalquote. a s yet. been no request to have "infinityIt stored in the accumulator when an overflow occurs. Furthermore. two times a r e printed. the obvious thing to do is to call the r e sult zero. It is hoped that the changes will be widely hailed a s improvements. the time printout tells how much time was spent in the execution of the packet and how much time has been spent in execution of SET o r SETSET packets since the birth of the system plus the time spent in the packet being finished. In the middle of February 1965 the system is complete and is available from Stanford. to be meaningful. The times a r e printed in minutes and milliseconds. - - - . (There has. with millisecond feature).5 system described in the LISP 1. This time printout. the amount of paper generated by a program with many constes is somewhat l e s s than formerly. but in a neat. and the printout may be reinstated by executing flVERBOS(*T*)tI.5 to be distributed by SHARE. the garbage collector printout may be suspended by executing "VERBOS(N1L)". Verbos and the Garbage Collector The garbage collector now prints its message in a single-spaced format. The system should be available from SHARE by the end of March 1965.APPENDIX I LISP FOR SHARE DISTRIBUTION The Artificial Intelligence Project at Stanford University has produced a version of LISP 1. but only in (generally) inessential details.5 P r o g r a m m e r ' s Manual.
Thus. The remainder of the trouble may be cured by executing "LISTING(NIL)ll. and a few cryptic remarks concerning the condition of the push-down list a t the time the e r r o r occurred.some of the blank space in the garbage collector printout will be used to output the number of function entrances which have taken place up to the time of the garbage collection. the printout may be reinstated by executing llLISTING(*T*)ll. then only the octal origin of the a s sembled code is printed. when the tracecount mechanism has been activated.) The printout is left-justified on the output page and has the form tl<functionname) (ORIGIN x x x ~ x Q ) ~ l . and these a r e both zero. This turns off the printout of the lap code generated by the compiler. Furthermore. two times. an e r r o r message. In such a situation. The l a p in the new system always prints the function name and the octal location in which the first word of the assembled function is stored. The value of -is still the symbol table. (If the assembled function is not a SUBR o r FSUBR. " TRACECOUNT(X)~~ (of those functions designated to be traced by the trace function call) to begin after x number of function entrances. one wishes he could begin tracing only a short time before the occurrence of the e r r o r . and the printing may be restored by executing uSYMTAB(*T*)ll. but. The use of the time and time1 functions has no effect on the times recorded by evalquote. in the same format that is used for the evalquote time printout. Tracecount (Alarm-Clock Trace) The t r a c e feature of LISP is quite useful. but the printing of the symbol table may lap be suspended by executing llSYMTAB(NIL)lt. And. llTIMEl()ltinitializes two time cells to zero and prints out. This phenomenon is familiar to those who have much at all to do with lap -. prints (again in the evalquote time printout format) the time since the last execution of "TIME()" and the time since the last execution of "TIMEl()".It is also possible to determine how much time is required to execute a given function. by execution of ltTRACECOUNT(x)ll. lap has not only returned the symbol table a s its value but has printed it out a s well. for a perfectly quiet compilation (except for the origin printout by lap). each time . one need only execute I1SYMTAB(NIL)l1 and LISTING(NIL)I1before compiling. with very little encouragement. it can be made to generate wastebaskets full of useless output. of course.o r the compiler. Non -Printing Compiler The problem of the verbosity of the compiler is only slightly abated by the symtab function. Often a programmer will find that his output (without tracing) consists of many lines of garbage collector printout. Lap and Symtab Heretofore. The causes the tracing tracecount function permits exactly this.
The functions tape.machines with 1/60 second core clocks add 50 seconds. Untime This routine is not available to the programmer. A4. only the first ten a r e used. A clock t r a p that would normally have occurred during the execution of the read o r write will be executed before the I/O operation takes place. Tape A few programmers with very large programs have long bemoaned the inability of LISP to communicate between different systems. The initial tape settings a r e . This situation would be intolerable i f the programmer were trying to save some definitions s o that he could use them later. To avoid this unpleasantness. but this is easily changed). A5. Space and Eject A small amount of additional control over the form of the data printed by LISP has been provided in the space and eject functions. where s is a list. B2. in essence. using the old system. mread. ttTAPE(s)tt. the number of function entrances accomplished before the e r r o r will be printed. The result is a skip to the top of the next page of output. the output of the print routine reverts to single -spacing. and the "END OF EVALQUOTE OPERATORntprintout again ejects the page before printing. the system I/O routines have been modified s o that the clock is. and backspace have been designed to alleviate this difficulty. A8. m p r h t . if more than ten a r e specified. tracing only the pertinent portion of the execution. ttSPACE(*T*)ttcauses all output to be double-spaced. a s it is called by Marvin Minsky of M.) enables a programmer to run a job (preceding the program by "TRACECOUNT(O)It). in particular. but its mention here may prevent some anxiety. and i f an e r r o r occurs. The tracecount feature (or alarm-clock trace. rewind. A7. one finds himself in the position of having part of one system and part of another stored in core o r on the SYSTMP.the arguments o r value of a traced function a r e printed the number of function entrances will be printed. from one to ten. A6. "EJECT()ttcauses a blank line with a carriage control character of 1 to be printed on the output tape. T. estimate the number of function entrances that occur before the program generates an e r r o r condition o r a wrong answer. The value of tape is its argument. and then run the job again. allows the user to specify up to ten scratch tapes. turned off during system 1/0 and three seconds is automatically added to the elapsed time a t the conclusion of the read o r write operation (in a machine with a millisecond core clock this is the case . nSPACE(NIL)urestores the spacing to its original status. -- -- . I. In the event that the program time estimate is exceeded during system I/O.
thus. The format of the output is identical to the normal LISP output. and three a r e to be tapes A4. B6. if the last tape function executed was 'ITAPE ((1204Q 2201Q))n. then wREWIND(2)11 will cause tape B1 to be rewound. a s specified in the most recently executed tape function. Evalquote Evalquote is available to the programmer a s a LISP function . execute "TAPE ((1204Q 2201Q 1205Q))I1. Caution in the u s e of this function is recommended.ers in the tape list without generating e r r o r s . the second digit must be a 2. rather than "(EVAL (QUOTE (APPEND (A)(B C D))) NIL)". one may now write I1(EVALQUOTE APPEND ((A)(BC D)))I1. for if an S-expression to be read from tape contains more than 72 characters. B5. Rewind llREWIND(x)w rewinds scratch tape x. Only the low-order fifteen bits of the numbers in +he tape list a r e used by the tape routines. - . the third and fourth a r e the octal representation of the unit number.B3. The value of mprint is the list printed. Mprint "MPRINT(x s ) I 1 prints the S-expression s on scratch tape x. two. should one desire to do so. to specify that scratch tapes one. F o r example. and A5. that i s . Thus. r the S-expression read. and is suitable for punching o r being read by mread. The value of rewind is NIL. The tapes must be specified by the octal number that occurs in the address portion of a machine-language instruction to rewind that tape. so it is possible to use decimal integers o r floatingpoint numb. a fourdigit octal number is required the first (high-order) digit is a 1 i f channel A is desired. The value of mread is . respectively. B1. The value of backspace is NIL. Mread NMREAD(x)lq e a d s one S-expression from scratch tape x. B4. Backspace llBACKSPACE(x)" causes scratch tape x to be backspaced one record. and single backspace will not move the tape all the way back to the beginning of the S-expression. except that sequence numbers a r e printed in the rightmost eight columns of the output line and the output line is only 80 c h a r a c t e r s long (the scratch tape output is generated by the punch routine). 2 i f channel B is desired. then it will occupy more than one record on the tape.
Reserved "RESERVED NILtt prints the names of the atoms on the object list in alphabetical order. Gensym and Symnam Gensym now omits leading zeroes from the numeric portions of the print-names of the symbols it generates. T. and "BACKTRACE xtl. s .Bac ktrace This function was copied (not quite literally) from M. thus. AAAAA1.. . and flags may be missed) on their property lists. the value of "BACKTRACE NILu i s the backtrace for the most recent e r r o r . restores the backtrace printout to the e r r o r routine. o r with none. AAAAA2. The new system causes the accumulator to be cleared i f an e r r o r occurs during the initial read-in.'s LISP system on the time-shared 7094. This function should help to solve some of the problems that a r i s e involving mysterious behavior of compiled functions that worked fine when interpreted. what once looked like ltGOOOO1ttnow prints a s ltGln. of all atom names he wants to retain in his personal LISP systems. defined results. . Read-In E r r o r s A common cause of free-storage o r circular list printouts i s an e r r o r (in parenthesis count. The argument of symnam 2)lt must have the indicator PNAME on i t s property list. AAAAA9. It SYMNAM(AAAAA)" causes gensym to produce distinct atoms with the following (not necessarily distinct) print-names: AAAAA1... Thus. s o that the contents of the accumulator a r e printed a s ttNIL1t. Obkeep Anyone desperate for a few more words of free storage may make up a list. suspends backtrace printouts when e r r o r s occur. for x not NIL. vSYMNAM(NIL)tl generated symbols to have purely numeric print-names (but they a r e not numbers). AAAAAO. it is possible to specify a heading word of from zero to six characters causes LISPfor the gensym symbols by executing symnam. I. The first call of backtrace. Furthermore. Backtrace is a function of no arguments in which the manner of specifying the no arguments constitutes.. . then execute (in a SET packet) "OBKEEP(s)". usually) during the initial read-in of a packet. with any argument. Thereafter.. along with the indicators (not alphabetized. tlSYMNAM(l will cause un- . in effect. an argument. The numeric portions of the print-names a r e truncated from the left so a s not to overlap the heading characters. Backtrace should always be evaluated by evalquote. All atoms except those which a r e members of s will be eliminated from the object list.
111CeI~ The differences between the new sublis and the old one. the for function because cset is used to set the index. . "FOR (index i s u dl dn)". evaluate s . Characteristics of the System The set-up deck supplied with the SHARE LISP system produces a system tape with the following properties: .. The final value of index is available outside . Sublis Sublis has been re-hand-compiled so that it behaves a s i f it were defined a s follows : null[x] e . eq[caar[x]. and u a r e numbers. [ and[equal[car[e]. s e t s index to the value of i and skips out of the following loop a s soon a s the value of u is not NIL: evaluate u.. suba[cdr [el]] -c e. the following "IF" forms a r e provided in the new system. evaluate d l .. .For the convenience of those who find i t difficult to get along with the tlCONDn form of the conditional statement. The value of the for statement i s the value of dn the last time it was evaluated.v] ]][suba[car [el]. a s far a s the programmer is concerned.v]] T -. for n l e s s than 17. "IF (a THEN b ELSE c)I1 and "IF (a b c)I1a r e equivalent to nCOND ((a b)(T c))". a r e that the new model is faster and the result shares a s much storage a s possible with e.e] cdar[x]. .. lambda[[u.equal[cdr[e]. evaluate dn. If i. then the . cons[u.- T - 111~~1.. "IF (a THEN b)n and "IF (a b)" a r e equivalent to "COND ((a b))".statement is similar to the ALGOL "for index = i for step s until u do begin dl dn endN..v]. go to the beginning of the loop. s. T subb[cdr[x]] .u].
- . SW6 off for e r r o r printout.Size (in words) Binary Program Space 14000 octal Push-Down List 5000 octal Full-Word Space 4220 octal F r e e Storage 22400 octal System Tape (SYSTAP) B7 System Temporary Tape (SYSTMP) B6 System Input Tape (SYSPIT) A2 System Output Tape (SYSPOT) A3 System Punch Tape (SYSPPT) A3 The console switches may be used to obtain special results: SW1 on for LISP input from on-line card reader SW2 has no effect SW3 on for LISP output on on-line printer SW4 has no effect SW5 on to suppress SYSPOT output SW6 on to return to overlord after accumulator printout resulting from e r r o r *I? 5*.
57 69.85 2. 57 32.88 3.87 18.87 86 69.FUNC TION PSEUDO-FUNCTION PREDICATE PREDICATE PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PREDICATE PSEUDO-FUNCTION PREDICATE APVAL PSEUDO-FUNCTION PREDICATE PSEUDO-FUNCTION . 23. 64 87 26.56 69.87 PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PREDICATE PSEUDO-FUNCTION PSEUDO-FUNCTION PREDICATE PSEUDO-FUNCTION PSEUDO. 56 3. 60 26.58 41.64 3.87 15. 26. 64 22. 59 59 69.59 30.64 21.85 64.76 61 18 2. 64 41.66 66 17.77 26.85 11.85 67 63 88 69.66 88 35.72 26. 85.64 88 21.88 69. 56 62 34.69 26.66 71 71 67. 64 69. 78 64. 58 11.INDEX T O FUNCTION DESCRIPTIONS Function ADD 1 ADVANCE AND APPEND APPLY ARRAY ATOM ATTRIB BLANK CAR CDR CHARCOUNT CLEARBUFF COMMA COMMON COMPILE CONC COND CONS COPY COUNT CP1 CSET CSETQ CURCHAR DASH DEFINE DEFLIST DIFFERENCE DIGIT DIVIDE DOLLAR DUMP EFFACE ENDREAD EOF EOR EQ EQSIGN EQUAL ERROR ERROR1 ERRORSET EVAL EVLIS EXCISE EXPT F FIXP FLAG FLOATP FUNCTION GENSYM GET GO GREATERP INTERN SUBR SUBR FSUBR SUBR SUBR SUBR SUBR SUBR APVAL SUBR SUBR APVAL SUBR APVAL SUBR SUBR FEXPR FSUBR SUBR SUBR SUBR SUBR EXPR FEXPR APVAL SUBR EXPR EXPR SUBR SUBR SUBR APVAL SUBR SUBR SUBR APVAL APVAL SUBR APVAL SUBR SUBR SUBR SUBR SUBR SUBR SUBR SUBR APVAL SUBR EXPR SUBR FSUBR SUBR SUBR FSUBR SUBR SUBR PSEUDO-FUNCTION PREDICATE PSEUDO-FUNCTION PREDICATE PSEUDO-FUNCTION Page 26. 57 59 69.71 66 41.61 70 27. 64 67. 58 26.
58 PSEUDO-FUNCTION 86 60 PSEUDO-FUNCTION 67 69.FUNCTION 67 25.75 PREDICATE 21. 23.64 PSEUDO-FUNCTION 65. 21. 58 PREDICATE PREDICATE 11. 18.84 PSEUDO-FUNCTION 65. 7 1 26.70 PSEUDO-FUNCTION 65.64 57 PREDICATE 87 PSEUDO-FUNCTION 67 27.84 PSEUDO-FUNCTION PSEUDO-FUNCTION LIBRARY 68 PSEUDO-FUNCTION LIBRARY 68. 64 26.INDEX T O FUNCTION DESCRIPTIONS Function LABEL LAP LEFTSHIFT LENGTH LESSP LIST LITER LOAD LOG AND LOGOR LOGXOR LPAR MAP MAPCON MAPLIST MAX MEMBER MIN MINUS MINUSP MKNAM NCONC NIL NOT NULL NUMBERP NUMOB OBLIST ONE P OPCHAR OPDEFINE OR PACK PAIR PAUSE PERIOD PLB PLUS PLUSS PRIN 1 PRINT PRINTPROP PROG PROG2 PROP PUNCH PUNCHDEF PUNCHLAP QUOTE QUOTIENT READ READLAP RECIP RECLAIM REMAINDER REMFLAG REMOB Page FSUBR SUBR SUBR SUBR SUBR FSUBR SUBR SUBR FSUBR FSUBR FSUBR APVAL SUBR SUBR SUBR FSUBR SUBR FSUBR SUBR SUBR SUBR SUBR APVAL SUBR SUBR SUBR SUBR APVAL SUBR SUBR EXPR FSUBR SUBR SUBR SUBR APVAL SUBR FSUBR APVAL SUBR SUBR EXPR FSUBR SUBR SUBR SUBR EXPR EXPR FSUBR SUBR SUBR SUBR SUBR SUBR SUBR SUBR SUBR - 8. 64 69.64 PSEUDO-FUNCTION 67 26.64 86 PSEUDO-FUNCTION 62 22.57 PREDICATE 26.64 27. 64 PSEUDO-FUNCTION 86 69 PREDICATE 26.85 FUNCTIONAL 63 FUNCTIONAL PSEUDO.69 21.62 26.66 FUNCTIONAL 59 65.71 42. 60 PSEUDO-FUNCTION 67 .64 PREDICATE 11.85 65.63 PREDICATE 26. 63 26. 22.63 69.76 10. 64 PREDICATE 87 PSEUDO-FUNCTION 65. 64 62 PREDICATE 26.76 26.84 PSEUDO-FUNCTION PSEUDO-FUNCTION LIBRARY 68 29.85 PSEUDO.FUNCTION 63 FUNCTIONAL 20. 64 PSEUDO-FUNCTION 41.84 PSEUDO-FUNCTION 65.73 27.64 26.
78 32.85 87 26.85 64.64 32. 79 LIBRARY 68 64.66 87 64.66 68 26.66 69.59 30.61 11.64 22. 78 34.69 PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PSETJDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO. 71 69.58 60 63 66 30.INDEX T O FUNCTION DESCRIPTIONS Function REMPROP RETURN REVERSE RPAR RPLACA RPLACD SASSOC SEARCH SELECT SET SETQ SLASH SPEAK SPECIAL STAR STARTREAD SUB1 SUBLIS SUBST T TEMPUS-FUGIT TERPRI TIMES TRACE TRACESET UNCOMMON UNCOUNT UNPACK UNSPECIAL UNTRACE UNTRACESET ZEROP *T* SUBR SUBR SUBR APVAL SUBR SUBR SUBR SUBR FEXPR SUBR FSUBR APVAL SUBR SUBR APVAL SUBR SUBR SUBR SUBR APVAL SUBR SUBR FSUBR EXPR EXPR SUBR SUBR SUBR SUBR EXPR EXPR SUBR APVAL PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION FUNCTIONAL FUNCTIONAL PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION PSEUDO-FUNCTION Page 41.FUNC TION PREDICATE . 71 30. 61 22.72 62 69. 78 34.66.58 41.85 41. 64 12.84 26.69 67 65.
OR. Examples: A NIL ATOM A1 METHIMPIKEHOSES A list of the names of functions that have been entered but not completed a t the time when an e r r o r occurs. For example. A synonym for association list. . This means that its value is the argument corresponding in position to the occurrence of the variable in the LAMBDA list. the LISP compiler does not need to compile an entire program before execution. The statements in an assembly language. a t om atomic symbol A synonym for atomic symbol. LAP. an assembly language allows the programmer to use symbols with mnemonic significance. The special forms involving AND. FAP . and recursion. digits. The legal atomic symbols a r e certain strings of letters. LISP was written in the assembly language. and special characters defined precisely in Appendix F. Example: ((VAR1 VAL1) (B (U V (W))) (C 2)) . a r e one to one with the machine language instructions to which they translate. back trace basic functions: c a r . cdr. Unlike most compilers. A procedure that is unambiguous and sufficiently mechanized s o a s to be programmable on a computer. in an expression of the form ((LAMBDA (X Y) E ) (QUOTE (A B)) (QUOTE C)). with few exceptions. cons. LISP contains ' a small internal assembly program. e 3 andatom Boolean form bound variable . It is used to pair bound variables with their values. and NOT. association list A list of pairs of terms which is equivalent to a table with two columns. which can be used to build up propositional expressions. .GLOSSARY Symbol or Term Algol 60 algorithm a-list assembly program Definition An international standard programming language for describing numerical computation. . Unlike machine language. A program that translates from a symbolic instruction language such a s FAP o r LAP into the language of a machine. The basic constituent of an S-expression. These functions a r e called basic because the entire class of computable functions of S-expressions can be built from them by using composition. conditional expressions. X has the value (A B) and Y the value C a t any of their occurrences in E : . It can compile individual functions defined by S-expressions into machine language during a run. compiler A program that translates from a source language into machine (or assembly) language. A variable included in the list of bound variables after LAMBDA is bound within the scope of the LAMBDA.
An expression that may be evaluated when some c o r r e spondence has been s e t up between the variables contained in it and a set of actual arguments. If a variable is to be evaluated by the interpreter. For definitions covering these three cases s e e bound v m e . This is usually written with nested brackets or parentheses. The value is the value of the entire conditional expression. A flag is not followed by a value a s an indicator is. maplist. the LISP interpreter . conditional expression constant dot notation doublet flag form free-storage list f r e e variable functional . The dot notation is the fundamental notation of LISP.GLOSSARY Symbol o r Term composition Definition To compose a function is to use the value of one function a s an argument for another function. and sassoc a r e functionals in LISP. search. The list notation is defined in t e r m s of the dot notation. The list of available words in the free storage of the computer memory. The important distinction between functions and forms i s treated in section 1 . the value of F i s always NIL. Other constants in the LISP system a r e described in Appendix A under the heading "APVAL. and a+(b. 4 . it must be bound a t some level o r have a constant value o r an assigned value. eval. A variable can be considered bound o r f r e e only within the context in which it appears. When the free-storage list is exhausted. A variable that is neither a program variable nor a bound variable. r a s an S-expression (CONS (CAR X) o (CDR Y)). Examples of different notations for conditional expression: M-expression: [a<0-b. TRACE and COMMON a r e flags. A symbol whose value does not change during a computation.cdr[~]]. Each time a cons is performed the first word on the free-storage list is removed. and constant. apply. An expression containing a list of propositional expressions and corresponding forms a s values. program variable. Examples: cons[car[~]. a new one is created by the garbage collector.* An item on the property list of an atomic symbol. A pair of arguments for evalquote.~-C] S-expression: (COND ((LESSP A 0) B) ( T C)) Algol 60: if a<O then b else c . " A method of writing S-expressions by combining only pairs of S-expressions rather than lists of indefinite length.(c+d)). For example. A function that can have functions a s arguments. and the value of 5 is always 5.
. FSUBR. This is in contrast to a translator o r compiler which translates a source-language program into machine language for subsequent execution. an]. )) . . . EXPR... ... In LISP. .GLOSSARY Symbol o r Term functional argument Definition A function that is an argument for a functional. . .form] garbage collector indicator interpreter lambda notation .. object Overlord packet A synonym for atomic symbol. . an indicator always has a property following i t . Each packet is preceded by an Overlord control card and ends with the ward STOP. list An S-expression satisfying the predicate listp[x] = null[x] J [not[atom[x]]/\listp[cdr [x]]] An S-expression of this form can be written ( m l . .. SPECIAL. LISP has both an interpreter and a compiler. An interpreter executes a source-language program by examining the source language and performing the specified algorithms. Unlike a flag. The monitor and system tape-handling section of the LISP system. . mn). The notation first used by Church for converting forms into names of functions.an is turned into the function of n variables whose arguments a r e in order ai by writing 1[[al. which stands for the dot-notation expression ( m l (m. list notation A method of writing S-expressions by using the form ( m l . . mZ. logical form M-expression See Boolian form An expression in the LISP language for writing functions of S-expressions.. M-expressions cannot be read by the machine a t present but must be hand-translated into S-expressions . .. mn) to stand for the dot -notation expression ( m l (m. . . and APVAL a r e examples of indicators.. . A form in a. An atomic symbol occurring on a property list that specifies that the next item on the list is a certain property. (mn NIL) .)) . A sequence of doublets for the interpreter. . and then collects all unneeded cells (garbage) into a free-storage list s o that these words can be used again. . m. a functional argument is quoted by using the special form The routine in LISP which identifies all active list structure by tracing it from fixed base cells and marking it.(mn NIL) . .
The list structure associated with an atomic symbol containing i t s print name and other properties. For example. In LISP the complement of the address of a word is called a pointer to that word. The symbols T and F have *T* and NIL a s values.a program) in one language (the source language) and whose output is a corresponding expression in another language (the object language). Program variables have initially the value NIL. pointer predicate A function whose value is true or false.GLOSSARY Svmbol or Term partial function Definition A function that is defined for only part of i t s normal domain. An expresssion or quantity associated with an atomic symbol. for such arguments. The relation between propositional expressions and predicates is exactly the same a s the relation between form and function. An expression that is true o r false when evaluated. but they can be assigned arbitrary S-expressions a s values by using SET o r SETQ. A debugging aid that causes a notice to be printed of every occurrence of an entry to o r exit from any of the specified functions. such a s i t s value a s a constant o r its definition a s a function. universal function . The last-in-first-out memory a r e a for saving partial results of recursive functions. RPLACA. In LISP true and false a r e represented by t E t o m i c symbols *T* and NIL. It is found on the property list preceded by an indicator. The technique of defining an algorithm in terms of itself. It may not be possible to decide exactly for which arguments the function is defined because. A variable that is declared in the list of variables following the word PROG. but has effects other than that of delivering its value. PRINT. . READ. A form having an indefinite number of arguments and/or arguments that a r e understood a s being quoted before being given to the special form to evaluate.. A function whose arguments a r e expressions representing any computable function and its arguments. with its appropriate arguments o r value. program variable property property list propositional expression pseudo -function push-down list reclaimer recursion special form trace translator A program whose input is an expression (e g . A program that is called a s i f it were a function. The value of the universal function is the value of the computable function applied to i t s arguments. A synonym for the garbage collector. the computation may continue indefinitely.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue listening from where you left off, or restart the preview.