BSD 3 development
[unix-history] / usr / doc / lisp / ch7.n
CommitLineData
7949960f
JF
1.ds e \s-2\e\s0
2.Lc The\ Reader 7
3.pp
4The
5.Fr
6reader is controlled by a
7.i readtable.
8A readtable is an array of fixnums, one fixnum for each of the 128
9ascii characters.
10The fixnums tell the reader what the properties of the each character
11are.
12The initial readtable is described below.
13The user may create new readtables using the
14.i makereadtable
15function.
16The current readtable is the value of the lisp
17symbol
18.i readtable
19which, like any lisp symbol, may be
20lambda bound to allow the user to change the
21reader syntax very quickly.
22The values which may appear in the readtable are:
23.TS
24center box;
25c | c | c | c
26ab | n | c | c .
27type value (decimal) meaning default
28=
29vnum 0 digit 0-9
30_
31vsign 1 plus or minus + -
32_
33vchar 2 alphabetic character T{
34A-Z a-z ^H ! $ % & * , / : ; < = > ? @ ^ _ ` { | } ~
35T}
36_
37vsca 66 single char atom none
38_
39vlpara 195 left paren (
40_
41vrpara 196 right paren )
42_
43vperd 197 period .
44_
45vlbrkt 198 left bracket [
46_
47vrbrkt 199 right bracket ]
48_
49veof 200 end of file rubout
50_
51vsq 201 single quote \'
52_
53vdq 138 T{
54double quote, all characters between matching double
55quotes are escaped (i.e. treated as \fBvchar\fP)
56T} "
57_
58vsd 137 T{
59string delimiter, all characters between matching
60delimiters are concated into an object of type string
61T} none
62_
63verr 203 illegal character T{
64null ^A-^I ^N-^Z ^\*e-^_
65T}
66_
67vsep 204 separator ^I-^M esc space
68_
69vspl 205 splicing macro character none
70_
71vmac 206 macro character none
72_
73vesc 143 escape character \*e
74.TE
75.pp
76The names in the type column are not known to Franz, we are just using them
77to tag the various classes. You must use the value in the second column.
78The default column shows the syntax values of characters in the raw lisp,
79i.e., the lisp which contains only machine language functions. The lisp
80which you get when you give the lisp command to the shell is an augmented
81version of the raw lisp, with additional lisp coded functions and changes
82in the readtable.
83The syntax changes in the lisp may differ from installation to installation
84but will probably include making one character be a comment character.
85In the lisp at Berkeley, semicolon is the comment character. This
86was done by declaring it to be a splicing macro character which
87invokes the function
88.i zapline
89when seen.
90.pp
91To read the syntax of a character, you may use
92(\fBstatus\ syntax\fP\ 's_char).
93.pp
94To change the syntax bits of a character, use the
95.i setsyntax
96function.
97There are two forms, one when you just want to change the syntax bits,
98and the other when you want to define a character macro.
99The first form is:
100.sp 1v
101.tl ''(\fBsetsyntax\fP \fI\'s_c \'x_value\fP)''
102.sp 1v
103Here
104.i s_c
105may be the character itself or it may be the fixnum representation
106of that character.
107.i x_value
108is one of the values given above in the second column.
109You should be careful when you change the syntax of a character
110as the change lasts until you explicitly change it back or until you
111begin with a new lisp.
112Also, some syntax changes are silly and will probably cause system
113errors (e.g. changing the syntax of an alphabetic character to be
114a
115.b vnum
116).
117The only syntax values you will probably ever use are:
118.b vdq
119and
120.b vesc.
121You should not change the syntax to
122.b vspl
123or
124.b vmac
125using the above form,
126instead it will be done automatically when you use the form below.
127.pp
128To declare a character macro use:
129.sp 1v
130.tl ''(\fBsetsyntax\fP \fI\'s_c \'s_type \'s_fcn\fP)''
131.sp 1v
132Where
133.i s_c
134is again either the character itself or its fixnum equivalent,
135type is
136.i splicing
137or
138.i macro,
139and
140.i s_fcn
141is either the name of
142a function expecting no arguments or is a lambda expression.
143The result of the setsyntax function is twofold: the readtable value
144for that character is changed to
145.b vspl
146or
147.b vmac,
148and the function
149is put on the property list of the character under the indicator "macro".
150The difference between a splicing macro and a macro is this: the value
151returned by a splicing macro is
152.i nconc ed
153to what has been read so far
154(i.e. (\fBnconc\fP\ sofar\ justreturned)),
155while the value returned by a macro is added to what has been read,
156(i.e (\fBnconc\fP\ sofar\ (\fBlist\fP justread)).
157Thus if a splicing macro returns nil, then it isn't seen since
158(\fBnconc\fP any nil)\ ==>\ any.
159In particular splicing macros are useful for conditional loading of
160lisp expressions.
161.pp
162.Fr
163treats left and right square brackets in a special way when
164building lists.
165A left bracket is just like a left parenthesis, and a right bracket
166matches a left bracket or all open left parentheses, whichever comes
167first.
168.pp
169When building atoms, a character with the syntax code
170.b vesc
171will cause the next character to be read in and treated as a
172.b vchar.
173To escape an entire string of characters, you surround them with matching
174characters
175having the
176.b vdq
177syntax code.
178To escape the
179.b vdq
180character within the string of characters you use any character of class
181.b vesc.
182The standard
183UNIX
184escape character, backslash (`\*e'), is in this class by default.