1
0
mirror of https://github.com/PDP-10/its.git synced 2026-02-02 06:51:04 +00:00
Files
PDP-10.its/src/teach/lesson.input
2018-10-28 16:47:17 -07:00

66 lines
2.4 KiB
Plaintext
Executable File

.comment -*- Mode:TEXT; -*-
.comment this lesson and its associate (OUTPUT) describe basic Lisp I/O.
.document INPUT - A description of some of the basic Lisp input functions.
.tag INPUT
Lesson INPUT, Version 2 Kent M. Pitman, 5/27/79
revised by Victoria Pigman, 9/1/82
Lisp, unlike almost all other languages, has a basic primitive for reading
itself (that is, for reading Lisp code). If you are a Fortran programmer,
imagine trying to write a function that reads and parses a Fortran statement
using Fortran to write the function. Yuck! Yet Lisp, the beautiful language
that it is, allows this to be done simply and painlessly.
*** Program and data in Lisp have exactly the same representation. ***
*** This is an important and useful feature! ***
The command for reading in a Lisp object is READ. It has two optional arguments
which you will not need to use until a later time since they are for doing
input and output from files. The simplest call to read is just (READ) and will
read an s-expression (ie, an atom or list) from the terminal.
.try
There is also a command for reading a single character at a time. This command
is called TYI. It is like the opposite of TYO (see the TYO command in the
lesson on output). Like many of the Lisp read commands, TYI also takes a
variable number of arguments but you will deal now only with the one argument
case. Note that what is returned by the TYI function is the numeric value of a
character. That numeric value can be fed to TYO in order to print it back out
later. For example, typing (TYI) will not do anything until you type another
character. At that time, it will read another character and return its
numeric value.
Try doing:
(TYI)A
.try
Now remember that "A" and "a" are not the same character. Try comparing the
result of
(TYI)A
with the result of
(TYI)a
and notice that different values come back.
.try
Just to verify that TYI and TYO are opposites, try doing this one:
(TYO (TYI))
Don't forget to type a character after it or it will just sit there
waiting for you...
.try
There is also a function like TYI that returns the character atom rather than
the numeric value of a character. This function is called READCH. The value
returned by READCH can be printed back out by the PRINC command. Try the
following:
(READCH)a
(READCH)A
and see how this differs from the TYI function above. Note that again
characters read in upper and lower cases are different.
.try
.next PROG