MTS 8: LISP and SLIP in MTS
Page Revised February 1979 June 1976
INPUT/OUTPUT IN LISP ____________________
Default I/O Operations ______________________
In the simplest application of LISP input/output, all input is read
from the system input device SCARDS, and all output is directed to the
system output device SPRINT. I/O is always treated as a stream, with
the syntactic boundaries between S-expressions, rather than physical
records, constituting the divisions between I/O operations. Thus,
several S-expressions may be read from one input line; one S-expression
may span several input lines. Similarly, the basic print function PRIN1
will "stream" output S-expressions into a single output buffer until it
overflows. Contents of the buffer will be printed, and the remainder of
the current expression will be continued as a new buffer.
(READ) Calling READ with no arguments causes one
S-expression to be read from the system input
device. The structure represented by the
S-expression will be returned.
(READCH) Gets the next character from the current input
stream. Blanks, periods, parentheses, etc., as well
as alphanumeric characters, are returned as one-
character atoms.
(READLINE) Causes a new line to be read from the system input
device into the system input buffer. The previous
contents of the buffer are destroyed, and the next
READ will begin with the new line. The value
returned from READLINE is a pointer to the buffer,
which is described in the next subsection.
(PRIN1 S) Causes the list or S-expression form of the LISP
structure S to be "printed" into the system output
buffer. Each S-expression printed will be preceded
by a blank. When the buffer is full, its contents
will be printed on the system output device, and
printing of the remainder of the print name of S
will be continued at the beginning of the empty
buffer.
The value returned from PRIN1 is S.
(TERPRI) Terminates the system output buffer, causing its
current contents (if any) to be printed, and the
buffer to be cleared. If there is nothing in the
buffer, TERPRI has no effect. The value of TERPRI
is NIL.
(PRINT S) Operates like (PROGN (TERPRI) (PRIN1 S) (TERPRI)),
except that the value returned from PRINT is S.
46 LISP

MTS 8: LISP and SLIP in MTS
June 1976
(TAB N) Causes the pointer for the system output buffer to
be moved to position N. (Position 1 is the first
position.) Any spaces skipped are filled with
blanks, and buffer contents skipped on a TAB to the
left are destroyed. The value returned from TAB is
the current buffer.
(SKIP N) Causes the pointer for the system output buffer to
be moved N spaces to the right. If N is negative,
the pointer moves to the left. Any spaces skipped
in a shift to the right are filled with blanks, and
buffer contents skipped over in a shift to the left
are destroyed. The value returned from SKIP is the
current buffer.
Note: TAB and SKIP cannot move a buffer pointer outside the buffer
range. If a TAB or SKIP indicates a move too far to the right or left,
an error will be generated.
Example:
(PROGN (PRIN1 ’THIS) (PRIN1 ’IS) (PRIN1 ’A) (PRIN1 ’TEST:) (TAB
35) (PRIN1 ’"THAT’S ALL") (TERPRI)) = NIL.
The following line will be printed:
THIS IS A TEST: THAT’S ALL
I/O Data Types ______________
LISP provides the option of a more flexible (and more complicated)
input/output scheme than the defaults described above. The basic data
structures involved in this scheme are the I/O destination atom, the
buffer, and the file.
I/O Destination Atoms
An I/O destination atom is a pointer atom whose VALUE is a
buffer/file pair to be used in an I/O operation. All of the I/O
functions described in the previous section accept such a pair as
an optional argument, and if given, the buffer/file pair are used
for that operation. Such a buffer/file pair is called an I/O
argument, or IOARG.
If an IOARG is given on input, data is read from the specified
buffer rather than the system input buffer; if the buffer is used
up, a new line is read from the specified file. On output, data is
printed into the specified bufer rather than the system output
buffer; if an overflow occurs (or the operation is a PRINT), data
is printed on the specified file.
LISP 47
Previous Page Next Page