MTS 8: LISP and SLIP in MTS Page Revised January 1983 June 1976 88 LISP
MTS 8: LISP and SLIP in MTS June 1976 THE LISP EDITOR _______________ INTRODUCTION ____________ The LISP editor is a LISP program designed to examine and modify LISP data structures, especially function definitions, as they exist within the LISP interpreter. It does not edit MTS files, although there are LISP editor commands which will read and write files on request. In the following section, the term "expression" refers to any LISP data structure (which is also known as an S-expression, denoting its external representation). The LISP editor has been checkpointed into the public file *LISPLIB. It is automatically restored and invoked, using a command of the form (EDIT fn) The value of EDIT is NIL. The argument "fn" determines the expression to edited as follows: (1) If "fn" is an atom with an EXPR on its property list, then the value of the EXPR property (normally a LAMBDA expression) is the expression to be edited. This is the normal method of editing function definitions. (2) Otherwise, "fn" itself is the expression to be edited. Since EDIT is an FSUBR, "fn" is not evaluated. Thus, the above form is not normally useful for editing arbitrary structures. APPLY or APPLY1 should be used instead, e.g., (APPLY1 ’EDIT list) where the value of "list" is the expression to be edited. The editor has its own command language; one or more commands may be entered on each line, separated by blanks. There are several variable length commands which must be separated from any subsequent commands on the same line by a colon (:). These are INSERT, DELETE, EXTRACT, ML, MR, BI, and BO, and are described in the subsection "Commands that Modify the Current Expression." Commands are read from *SOURCE* using the prefix character period (.), and output is written on *SINK*, using the prefix colon. All editor commands operate on a subexpression of the original argument to EDIT; this subexpression is called the current expression. _______ __________ There are several commands available for specifying the current expres- sion. They are described in later in this section. The LISP Editor 89
MTS 8: LISP and SLIP in MTS Page Revised January 1983 June 1976 88 LISP
MTS 8: LISP and SLIP in MTS June 1976 THE LISP EDITOR _______________ INTRODUCTION ____________ The LISP editor is a LISP program designed to examine and modify LISP data structures, especially function definitions, as they exist within the LISP interpreter. It does not edit MTS files, although there are LISP editor commands which will read and write files on request. In the following section, the term "expression" refers to any LISP data structure (which is also known as an S-expression, denoting its external representation). The LISP editor has been checkpointed into the public file *LISPLIB. It is automatically restored and invoked, using a command of the form (EDIT fn) The value of EDIT is NIL. The argument "fn" determines the expression to edited as follows: (1) If "fn" is an atom with an EXPR on its property list, then the value of the EXPR property (normally a LAMBDA expression) is the expression to be edited. This is the normal method of editing function definitions. (2) Otherwise, "fn" itself is the expression to be edited. Since EDIT is an FSUBR, "fn" is not evaluated. Thus, the above form is not normally useful for editing arbitrary structures. APPLY or APPLY1 should be used instead, e.g., (APPLY1 ’EDIT list) where the value of "list" is the expression to be edited. The editor has its own command language; one or more commands may be entered on each line, separated by blanks. There are several variable length commands which must be separated from any subsequent commands on the same line by a colon (:). These are INSERT, DELETE, EXTRACT, ML, MR, BI, and BO, and are described in the subsection "Commands that Modify the Current Expression." Commands are read from *SOURCE* using the prefix character period (.), and output is written on *SINK*, using the prefix colon. All editor commands operate on a subexpression of the original argument to EDIT; this subexpression is called the current expression. _______ __________ There are several commands available for specifying the current expres- sion. They are described in later in this section. The LISP Editor 89
MTS 8: LISP and SLIP in MTS June 1976 Ignoring dotted pairs for the moment, any proper subexpression of a LISP expression (hence any current expression) must be one of the following: (1) An atom. (2) A list which is an element of some higher level list. (3) A proper sublist, which will be referred to as the tail of a ____ list. For example, given the expression (A (B C) D), the atoms are A, B, C, and D; the list (B C) is an element of the top-level list; the tails of (A (B C) D) are ((B C) D) and (D); and the tail of (B C) is (C). Dotted pairs (expressions whose CDR are atoms other than NIL) have not been adequately described, and indeed, the behavior of the editor is erratic at best when it encounters a dotted pair. For the purpose of this description, editor commands are divided into five major groups: printing commands, commands specifying the current expression, commands modifying the current expression, commands undoing previous modifications, and miscellaneous commands. COMMANDS THAT PRINT THE CURRENT EXPRESSION __________________________________________ Command: P [n] The P command prints the current expression up to level "n". The optional argument n defaults to 2. To avoid excessive output, lists at level n are printed as the character ampersand (&). A current expression which is a tail of some list is indicated by ellipsis marks (...) preceding the expression. A P command is assumed at the end of every line unless a P, ?, or PP command is the last command on the line. Command: ? The ? command is equivalent to a P 1000 command; it effectively prints the entire current expression. This command is used in most of the examples in this section. Command: PP The PP command also prints the entire current expression, but in an indented format which makes the structure more clearly visible. The PP command does not print ellipsis marks for tails of lists. 90 The LISP Editor
MTS 8: LISP and SLIP in MTS June 1976 Page Revised February 1979 Examples: .? :(LAMBDA (X) (COND ((NULL X) NIL) (T (CONS X X)))) .P :(LAMBDA (X) (COND & &)) .P 3 :LAMBDA (X) (COND (& NIL) (T &))) .PP :(LAMBDA (X) : (COND ((NULL X) NIL) : (T (CONS X X)))) COMMANDS THAT SPECIFY THE CURRENT EXPRESSION ____________________________________________ Command: [±]n A positive integer "n" or "+n" selects the nth element of the current expression, counting from the left, and makes it the current expression. A negative integer "-n" operates in the same manner except that it counts from the right. Users should note that zero is a separate command, described later in this section. Examples: .? :(LAMBDA (X) (COND ((NULL X) NIL) (T (CONS X X)))) .3 ? :(COND ((NULL X) NIL) (T (CONS X X))) .2 1 ? :(NULL X) Command: UP If the current expression is an element of a higher-level list, the UP command specifies the tail of the higher-level list beginning with the current expression, as the new current expression. Otherwise, the UP command has no effect. Note that if the current expression is the first element of a higher-level list, the UP command produces the entire list, rather than just a tail of the list. Examples: .? :(LAMBDA (X) (COND ((NULL X) NIL) (T (CONS X X )))) .3 ? | :(COND ((NULL X) NIL) (T (CONS X X))) The LISP Editor 91
MTS 8: LISP and SLIP in MTS Page Revised January 1983 June 1976 (DECLARE F =CHECK) then when it is compiled, the generated code will include a test to check that the correct number of arguments was passed to the function, and various other error checks (for valid atomic, list, or numeric arguments, etc.) will be made. Normally, little or no error checking is performed by compiled programs. If the variable =CHECK is set to T, all functions will be compiled as if they had been declared =CHECK. Functions Known to the Compiler The following functions have fixed definitions within compiled code: ABS ADD ADD1 AND APPLY APPLY1 ARG ASSOC ATOM C...R COND CONS IDIVIDE EQ EQUAL EVAL EVEN GET GO GRAFT GREATER LAND LESS LENGTH LIST LOR LXOR MAP MAPC MAPCAN MAPCAR MAPCON MAPLIST MAX MEMBER MIN MINUS NOT NTH NUMBER OR PROG PROGN PUT QUOTE REMAIN REPEAT RETURN REVERSE SELECT SET SETA SETQ SHIFT SUB SUB1 TIMES UNCONS ZERO The following functions are declared to be fixed-link functions: | CHECKPOINT, COPY, DECLARE, DEFUN, DISPLAY, LABEL, MODIFY, | NEWWORLD, OBLIST, OPEN, REALWORLD, REM, REMOB, SETA2, SETQ2, | STATUS, TRACE, UNTRACE, Limitations and Warnings (1) General Warning: Compiled functions do a minimum of error checking, so users are advised to debug their programs before compiling them. Unless the =CHECK option is used, the normal checks for undefined variables, bad atomic, list, and numeric arguments, array dimensions exceeding legal limits, etc., do not occur in compiled code. (2) Since fixed-link functions are not executed under control of EVAL, debugging features such as TRACE, BUG, and STEP cannot be used with them. (3) An APPLY of a no-spread macro or LAMBDA-expression cannot be compiled. (Use APPLY1 instead.) (4) Functions used as macros may not be recursive. An attempt to compile a recursive MACRO will generate an error. 86 LISP
MTS 8: LISP and SLIP in MTS June 1976 Page Revised January 1983 (5) Each internal block must be less than one page in length. If the compiler finds that a block is too long, it will terminate with an error message. The user can then break the program downinto smaller blocks and recompile. Note: Experience indi- cates that about 50-75 lines of LISP code (uninterrupted by internal blocks) will compile into one page. (6) The total number of blocks in one compiled routine cannot exceed 150. (7) The number of bytes in the first block of a program, plus the number of special variables, times four, must be less than 4096. (8) The number of local variables defined at one time cannot exceed 1020. (9) The compiler occupies 40 pages of memory, and compilation of even a small program is likely to increase storage to 50 pages. After EXCISing (using the =EXCISE function described above) the compiler, the user may want to compress his core usage by performing a CHECKPOINT. (10) Functions which depend on calls to EVAL, such as UNEVAL and RETURN with a second argument, may not operate in the same manner when called from a compiled program, since many function calls are compiled directly and do not generate calls to EVAL. (11) The compiler does not process the LABEL function, hence the use of LABELs in compiled programs is not recommended. If a LABEL is encountered, the compiler generates a call to the interpreter. Other Special Features ______________________ The functions EDIT and DEBUG provide access to a LISP editor and debugging package. These features are documented in the sections "The LISP Editor" and "LISP Debugging Facilities" in this volume. LISP 87