1 V-mode LISP PE-TI-599 DATE: April 5, 1979 SUBJECT: V-mode LISP REFERENCE: None ABSTRACT + ________ V-Mode LISP is an implementation of LISP1.5, minus implementation dependent features and with some syntactic extensions. This document is intended to enable users who are familiar with LISP to invoke the interpreter and run LISP programs. Readers who are not familiar with LISP should consult one of the standard primers. The bibliography contains references. V-mode LISP is neither a supported product nor a funded project. Many aspects of the system, especially implementation details, are likely to change. Persons interested in helping to extend V-mode LISP are invited to participate. Some documentation is available which describes system internals. 1 V-mode LISP PE-TI-599 Table of Contents + _________________ 1 Invocation..........................................................3 2 Input Format........................................................4 3 Atoms...............................................................6 4 Environment.........................................................7 5 Lambda and Nlambda Expressions......................................8 6 Backtrace...........................................................9 7 Routines Currently Available.......................................10 8 Planned Extensions.................................................12 9 Bibliography.......................................................13 Page 2 1 V-mode LISP PE-TI-599 1 Invocation SEG LARRY>#LISP (for now, at least) causes LISP to begin executing. LISP responds with a version message and a newline, and then reads successive s-expressions from the terminal, evaluates each in turn, and prints the resulting value. In the following sample terminal session, the vertical bars denote lines printed by the interpreter. OK, seg larry>#lisp | V-mode LISP March 18, 1979 - fixed 'embedded lambda' bug (plus 3 4) | 7 (cons 'a 'b) | (a . b) (cons a 'b) | (() . b) (setq a 'value_of_a) | value_of_a (cons a 'b) | (value_of_a . b) (quit) | Unallocated list storage 4027(0)/1470 OK, como -e Page 3 1 V-mode LISP PE-TI-599 2 Input Format Spaces, tabs, and newlines (in fact, all control characters) are significant only for delimiting atoms from each other. They may be used freely to improve readability. Erase and kill characters have their usual effect. Upper and lower case characters are distinguished. In particular, the special atom t and all the builtin functions are all spelled in lower + _ _____ case. + ____ The interpreter does not begin evaluation until a complete s-expression has been read, i.e. until the parentheses match. Extra right parentheses are ignored. Successive s-expressions on the same input line are evaluated in succession. An expression of the form (a1 a2 a3 . a4) is read in as equivalent to (a1 . (a2 . (a3 . a4))) as an extension to the usual convention for representing lists. In particular, (a1 a2 a3 . ()) is equivalent to (a1 a2 a3) The form ' is read in as (quote ) in the usual convention. The builtin function co, applied to an argument which evaluates to a + __ non-numeric atom, causes the next s-expressions to be read from the file of the same name as the atom. End of file causes the input stream to revert to its previous source (i.e. no equivalent to COMO -E is required). Treenames (but not passwords) are accepted. A file read by co may contain uses of co, and these may be nested up to 20 levels. If + __ __ the last s-expression in a file is incomplete, the LISP read routine will supply enough right parentheses to complete it. Page 4 1 V-mode LISP PE-TI-599 In standard LISP, each clause of a cond is a two element list where the + ____ result of evaluating the first element determines whether the second should be evaluated. V-mode LISP extends this concept so that a cond + ____ clause may contain an indefinite number of expressions following the first element. These are evaluated, in order, providing that the result of evaluating the first element is not (). The result of the cond expression is the value of the last expression thus evaluated. + ____ Page 5 1 V-mode LISP PE-TI-599 3 Atoms Atoms are delimited by a control character, space, single quote, ".", "(", or ")". A character quoting mechanism is planned which will allow users to place special characters within atom names. Users should avoid the casual use of the characters " and \ within atom names, since these will be the escape characters. Numeric atoms are those which begin with a digit. They are read in as decimal numbers, and are stored as single precision integers. Non-numeric atoms are limited to 80 characters. Page 6 1 V-mode LISP PE-TI-599 4 Environment The environment is implemented as an association list, usually known as + ________________ an a-list, consisting of pairs. The a-list has + ______ permanent and temporary sections, of which the temporary section is searched first when looking up the value of a variable. The primitives cset, csetq, defun, and ndefun always affect the permanent section of + ____ _____ _____ ______ the a-list. set and setq affect the most recent binding of a given + ___ ____ variable, if a binding exists; otherwise one is created in the permanent a-list. The default value of any non-numeric atom which has not otherwise been defined (by (n)lambda binding, set, setq, defun, etc.) is (). Page 7 1 V-mode LISP PE-TI-599 5 Lambda and Nlambda Expressions User-defined functions are represented as lambda or nlambda expressions, whose forms are (lambda ) (nlambda ) In each case, the application of the (n)lambda expression to arguments causes the evaluation of the of the expression in an environment augmented by the binding of variable(s) on the to the argument(s). Nlambda expressions differ from lambda expressions in that the bound variables of an nlambda expression are bound to unevaluated arguments. + ___________ The of a lambda or nlambda expression may take several forms. If the consists of a single atom, the list of (evaluated or unevaluated) arguments is bound to the atom. If the consists of a list of atoms terminated by an atom (i.e. (a b . c)) then the terminating atom is bound to the remainder of the (evaluated or unevaluated) argument list after the previous members of the have been bound. These forms are useful for defining functions which may take a varying number of arguments. In a (n)lambda combination, missing arguments cause their corresponding variables to be bound to (). Extra arguments are ignored. The builtin pseudofunctions defun and ndefun are provided for user + _____ ______ convenience in defining functions. Evaluation of the expression (defun ) causes the value of in the permanent a-list to be (lambda ) Use of ndefun in analogous fashion causes the value of the function + ______ name to be an nlambda expression. Neither defun nor ndefun causes its + _____ ______ arguments to be evaluated as the function is being defined. Page 8 1 V-mode LISP PE-TI-599 6 Backtrace The interpreter keeps track of successive expressions which are passed to recursive invocations of eval. If a semantic error occurs, and the + ____ backtrace flag is on, the interpreter prints a backtrace of the + __ expressions passed to eval. The backtrace flag is initialized to be on + __ by default, and can be changed by using the backtrace primitive + _________ operator as follows: (backtrace t) turns the backtrace flag on (any non-null argument will do), and + __ (backtrace) turns the backtrace flag off. + ___ Page 9 1 V-mode LISP PE-TI-599 7 Routines Currently Available These are the routines which currently exist, either as builtin functions, internal evaluator routines, or both. subrs are user-callable builtin functions which get their argument(s) + ____ evaluated before they are passed. fsubrs are passed unevaluated + _____ argument(s). exprs and fexprs are lambda and nlambda expressions, + ____ _____ respectively, which are values bound to variables on the a-list. add1 subr. the arithmetic successor function. atom subr. return t if argument is atomic + _ atomp returns '1'b if its argument is atomic backtrace subr. turns error backtrace on or off bldin used to put subr or fsubr on permanent alist car subr. take car of a list cdr subr. take cdr of a list c..r subrs - all compositions of car's and cdr's to level 3 co subr expects atomic argument which is name of file to be read cond fsubr which does conditional evaluation cons subr which creates new cell with designated car, cdr cset subr. set value of arg1 on permanent alist to be arg2 csetq fsubr. same as cset, but don't evaluate variable name defun fsubr which defines an expr eq subr predicate returns t if args are identical + _ eqp returns '1'b if its 2 args are eq to each other equal subr returns t if args are isomorphic + _ equalp returns '1'b if args are isomorphic error prints char(80) var error message, s-expr; triggers backtrace eval subr. if 2nd arg is null(), use current environment. greaterp subr returns t if arg1 > arg2 + _ id identity function used for list, quote intern given char(80) var argument, return atom value. length subr returns top-level length of a list lessp subr returns t if arg1 < arg2 + _ main top level routine - does initialization, listen loop memalist auxilliary used to lookup variable on alist minus subr performs unary minus or multiple subtraction ndefun fsubr defines fexpr on permanent alist new_bind auxilliary to create new binding on an alist null subr returns t if its arg is (), () otherwise + _ numberp subr returns t if its arg is a number + _ numberpp returns '1'b if its arg is a number plus subr adds any number of args prin1 subr. print s-expr without newline. returns its argument. print subr. print s-expr with newline. returns its argument. quit fsubr. exit to PRIMOS. quotient subr return arg1 / arg2 (integer divide) read subr. ignores args, if any, returns s-expr read from input rplaca subr replace car of arg1 by arg2 rplacd subr replace cdr of arg1 by arg2 set subr set value of variable arg1 to be arg2 on current alist Page 10 1 V-mode LISP PE-TI-599 setq fsubr same as set but don't evaluate variable name sub1 subr arithmetic predecessor function times subr multiply any number of arguments version fsubr returns (), prints version message zerop subr return t if arg is 0 + _ Also, the atoms + - * / < > are bound to the same subrs as plus, minus, times, quotient, lessp, and greaterp respectively. Page 11 1 V-mode LISP PE-TI-599 8 Planned Extensions The extensions we envision making their way into V-mode LISP fall into the following general categories: (1) input extensions, such as the character quoting mechanism mentioned above. (2) additional builtin functions. (3) garbage collection. (4) the standard LISP imperative control structures: prog, progn, + ____ _____ return, while, go. + ______ _____ __ (5) a compiler and linking mechanism. (6) tracing and timing facilities. There are no schedules or target dates for any of these features. Page 12 1 V-mode LISP PE-TI-599 9 Bibliography John McCarthy et al, LISP 1.5 Programmer's Manual, M.I.T. Press, + ____________________________ Cambridge, Massachusetts Clark Weissman, LISP 1.5 Primer, Dickenson Publishing, Belmont, + _______________ California Page 13