BSD 4_3 development
[unix-history] / usr / lib / lisp / manual / ch13.r
CommitLineData
f9a8037d
C
1
2
3
4
5
6
7
8 CHAPTER 13
9
10
11 The CMU User Toplevel and the File Package
12
13
14
15This documentation was written by Don Cohen, and the func-
16tions described below were imported from PDP-10 CMULisp.
17
18_\bN_\bo_\bn _\bC_\bM_\bU _\bu_\bs_\be_\br_\bs _\bn_\bo_\bt_\be: this is not the default top level for
19your Lisp system. In order to start up this top level, you
20should type (_\bl_\bo_\ba_\bd '_\bc_\bm_\bu_\be_\bn_\bv).
21
22
23
24
25 13.1. User Command Input Top Level
26
27 The top-level is the function that reads what you
28 type, evaluates it and prints the result. The _\bn_\be_\bw_\bl_\bi_\bs_\bp
29 top-level was inspired by the CMULisp top-level (which
30 was inspired by interlisp) but is much simpler. The
31 top-level is a function (of zero arguments) that can
32 be called by your program. If you prefer another
33 top-level, just redefine the top-level function and
34 type "(reset)" to start running it. The current top-
35 level simply calls the functions tlread, tleval and
36 tlprint to read, evaluate and print. These are sup-
37 posed to be replaceable by the user. The only one
38 that would make sense to replace is tlprint, which
39 currently uses a function that refuses to go below a
40 certain level and prints "...]" when it finds itself
41 printing a circular list. One might want to pretty-
42 print the results instead. The current top-level
43 numbers the lines that you type to it, and remembers
44 the last n "events" (where n can be set but is
45 defaulted to 25). One can refer to these events in
46 the following "top-level commands":
47
48
49
50
51
52
53
54
55
56
57
58
59
60\e9
61
62\e9The CMU User Toplevel and the File Package 13-1
63
64
65
66
67
68
69
70The CMU User Toplevel and the File Package 13-2
71
72
73
74 ____________________________________________________
75
76 _\bT_\bO_\bP_\bL_\bE_\bV_\bE_\bL _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY
77
78 ?? prints events - both the input and the result. If you just type
79 "??" you will see all of the recorded events. "?? 3" will show
80 only event 3, and "?? 3 6" will show events 3 through 6.
81
82 redo pretends that you typed the same thing that was typed before. If
83 you type "redo 3" event number 3 is redone. "redo -3" redoes the
84 thing 3 events ago. "redo" is the same as "redo -1".
85
86 ed calls the editor and then does whatever the editor returns. Thus
87 if you want to do event 5 again except for some small change, you
88 can type "ed 5", make the change and leave the editor. "ed -3"
89 and "ed" are analogous to redo.
90 ____________________________________________________
91
92
93
94Finally, you can get the value of event 7 with the function
95(valueof 7). The other interesting feature of the top-level
96is that it makes outermost parentheses superfluous for the
97most part. This works the same way as in CMULisp, so you
98can use the help for an explanation. If you're not sure and
99don't want to risk it you can always just include the
100parentheses.
101
102
103(top-level)
104
105 SIDE EFFECT: _\bt_\bo_\bp-_\bl_\be_\bv_\be_\bl is the LISP top level function.
106 As well as being the top level function
107 with which the user interacts, it can be
108 called recursively by the user or any
109 function. Thus, the top level can be
110 invoked from inside the editor, break
111 package, or a user function to make its
112 commands available to the user.
113
114 NOTE: The CMU FRANZ LISP top-level uses _\bl_\bi_\bn_\be_\br_\be_\ba_\bd
115 rather than _\br_\be_\ba_\bd. The difference will not usu-
116 ally be noticeable. The principal thing to be
117 careful about is that input to the function or
118 system being called cannot appear on the same
119 line as the top-level call. For example, typing
120 (_\be_\bd_\bi_\bt_\bf _\bf_\bo_\bo)_\bf_\bP _\bo_\bn _\bo_\bn_\be _\bl_\bi_\bn_\be _\bw_\bi_\bl_\bl _\be_\bd_\bi_\bt _\bf_\bo_\bo _\ba_\bn_\bd
121 _\be_\bv_\ba_\bl_\bu_\ba_\bt_\be _\bP, _\bn_\bo_\bt _\be_\bd_\bi_\bt _\bf_\bo_\bo _\ba_\bn_\bd _\be_\bx_\be_\bc_\bu_\bt_\be _\bt_\bh_\be _\bp _\bc_\bo_\bm_\b-
122 _\bm_\ba_\bn_\bd _\bi_\bn _\bt_\bh_\be _\be_\bd_\bi_\bt_\bo_\br. _\bt_\bo_\bp-_\bl_\be_\bv_\be_\bl _\bs_\bp_\be_\bc_\bi_\ba_\bl_\bl_\by _\br_\be_\bc_\bo_\bg_\b-
123 _\bn_\bi_\bz_\be_\bs _\bt_\bh_\be _\bf_\bo_\bl_\bl_\bo_\bw_\bi_\bn_\bg _\bc_\bo_\bm_\bm_\ba_\bn_\bd_\bs:
124
125\e9
126
127\e9 Printed: July 21, 1983
128
129
130
131
132
133
134
135The CMU User Toplevel and the File Package 13-3
136
137
138(valueof '_\bg__\be_\bv_\be_\bn_\bt_\bs_\bp_\be_\bc)
139
140 RETURNS: the value(s) of the event(s) specified by
141 g_eventspec. If a single event is specified,
142 its value will be returned. If more than one
143 event is specified, or an event has more than
144 one subevent (as for _\br_\be_\bd_\bo, etc), a list of
145 vlaues will be returned.
146
147
148
149
150 13.2. The File Package
151
152 Users typically define functions in lisp and then want
153 to save them for the next session. If you do
154 (_\bc_\bh_\ba_\bn_\bg_\be_\bs), a list of the functions that are newly
155 defined or changed will be printed. When you type
156 (_\bd_\bs_\bk_\bo_\bu_\bt_\bs), the functions associated with files will be
157 saved in the new versions of those files. In order to
158 associate functions with files you can either add them
159 to the _\bf_\bi_\bl_\be_\bf_\bn_\bs list of an existing file or create a
160 new file to hold them. This is done with the _\bf_\bi_\bl_\be
161 function. If you type (_\bf_\bi_\bl_\be _\bn_\be_\bw) the system will
162 create a variable called _\bn_\be_\bw_\bf_\bn_\bs. You may add the
163 names of the functions to go into that file to _\bn_\be_\bw_\bf_\bn_\bs.
164 After you do (_\bc_\bh_\ba_\bn_\bg_\be_\bs), the functions which are in no
165 other file are stored in the value of the atom
166 _\bc_\bh_\ba_\bn_\bg_\be_\bs. To put these all in the new file, (_\bs_\be_\bt_\bq
167 _\bn_\be_\bw_\bf_\bn_\bs (_\ba_\bp_\bp_\be_\bn_\bd _\bn_\be_\bw_\bf_\bn_\bs _\bc_\bh_\ba_\bn_\bg_\be_\bs)). Now if you do
168 (_\bc_\bh_\ba_\bn_\bg_\be_\bs), all of the changed functions should be
169 associated with files. In order to save the changes
170 on the files, do (_\bd_\bs_\bk_\bo_\bu_\bt_\bs). All of the changed files
171 (such as NEW) will be written. To recover the new
172 functions the next time you run FRANZ LISP, do (_\bd_\bs_\bk_\bi_\bn
173 _\bn_\be_\bw).
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190\e9
191
192\e9 Printed: July 21, 1983
193
194
195
196
197
198
199
200The CMU User Toplevel and the File Package 13-4
201
202
203
204 ____________________________________________________
205
206 Script started on Sat Mar 14 11:50:32 1981
207 $ newlisp
208 Welcome to newlisp...
209 1.(defun square (x) (* x x)) ; define a new function
210 square
211 2.(changes) ; See, this function is associated
212 ; with no file.
213 <no-file> (square)nil
214 3.(file 'new) ; So let's declare file NEW.
215 new
216 4.newfns ; It doesn't have anything on it yet.
217 nil
218 5.(setq newfns '(square)) ; Add the function associated
219 (square) ; with no file to file NEW.
220 6.(changes) ; CHANGES magically notices this fact.
221
222 new (square)nil
223 7.(dskouts) ; We write the file.
224 creating new
225 (new)
226 8.(dskin new) ; We read it in!
227 (new)
228 14.Bye
229 $
230 script done on Sat Mar 14 11:51:48 1981
231
232 ____________________________________________________
233
234
235
236
237
238(changes s_flag)
239
240 RETURNS: Changes computes a list containing an entry
241 for each file which defines atoms that have
242 been marked changed. The entry contains the
243 file name and the changed atoms defined
244 therein. There is also a special entry for
245 changes to atoms which are not defined in any
246 known file. The global variable _\bf_\bi_\bl_\be_\bl_\bs_\bt con-
247 tains the list of "known" files. If no flag
248 is passed this result is printed in human
249 readable form and the value returned is t if
250 there were any changes and nil if not. Other-
251 wise nothing is printed and the computer list
252 is returned. The global variable _\bc_\bh_\ba_\bn_\bg_\be_\bs con-
253 tains the atoms which are marked changed but
254 not yet associated with any file. The _\bc_\bh_\ba_\bn_\bg_\be_\bs
255 function attempts to associate these names
256
257
258 Printed: July 21, 1983
259
260
261
262
263
264
265
266The CMU User Toplevel and the File Package 13-5
267
268
269 with files, and any that are not found are
270 considered to belong to no file. The _\bc_\bh_\ba_\bn_\bg_\be_\bs
271 property is the means by which changed func-
272 tions are associated with files. When a file
273 is read in or written out its _\bc_\bh_\ba_\bn_\bg_\be_\bs property
274 is removed.
275
276(dc s_word s_id [ g_descriptor1 ... ] <text> <esc>)
277
278 RETURNS: _\bd_\bc defines comments. It is exceptional in
279 that its behavior is very context dependent.
280 When _\bd_\bc is executed from _\bd_\bs_\bk_\bi_\bn it simply
281 records the fact that the comment exists. It
282 is expected that in interactive mode comments
283 will be found via _\bg_\be_\bt_\bd_\be_\bf - this allows large
284 comments which do not take up space in your
285 core image. When _\bd_\bc is executed from the ter-
286 minal it expects you to type a comment. _\bd_\bs_\bk_\bo_\bu_\bt
287 will write out the comments that you define
288 and also copy the comments on the old version
289 of the file, so that the new version will keep
290 the old comments even though they were never
291 actually brought into core. The optional id
292 is a mechanism for distinguishing among
293 several comments associated with the same
294 word. It defaults to nil. However if you
295 define two comments with the same id, the
296 second is considered to be a replacement for
297 the first. The behavior of _\bd_\bc is determined by
298 the value of the global variable _\bd_\be_\bf-_\bc_\bo_\bm_\bm_\be_\bn_\bt.
299 _\bd_\be_\bf-_\bc_\bo_\bm_\bm_\be_\bn_\bt contains the name of a function
300 that is run. Its arguments are the word, id
301 and attribute list. _\bd_\be_\bf-_\bc_\bo_\bm_\bm_\be_\bn_\bt is initially
302 _\bd_\bc-_\bd_\be_\bf_\bi_\bn_\be. Other functions rebind it to _\bd_\bc-
303 _\bh_\be_\bl_\bp, _\bd_\bc-_\bu_\bs_\be_\br_\bh_\be_\bl_\bp, and the value of _\bd_\bs_\bk_\bi_\bn-
304 _\bc_\bo_\bm_\bm_\be_\bn_\bt. The comment property of an atom is a
305 list of entries, each representing one com-
306 ment. Atomic entries are assumed to be iden-
307 tifiers of comments on a file but not in core.
308 In-core comments are represented by a list of
309 the id, the attribute list and the comment
310 text. The comment text is an uninterned atom.
311 Comments may be deleted or reordered by edit-
312 ing the comment property.
313
314
315
316
317
318
319
320
321\e9
322
323\e9 Printed: July 21, 1983
324
325
326
327
328
329
330
331The CMU User Toplevel and the File Package 13-6
332
333
334(dskin l_filenames)
335
336 SIDE EFFECT: READ-EVAL-PRINTs the contents of the
337 given files. This is the function to use
338 to read files created by _\bd_\bs_\bk_\bo_\bu_\bt. _\bd_\bs_\bk_\bi_\bn
339 also declares the files that it reads (if
340 a _\bf_\bi_\bl_\be-_\bf_\bn_\bs list is defined and the file is
341 otherwise declarable by _\bf_\bi_\bl_\be ), so that
342 changes to it can be recorded.
343
344
345(dskout s_file1 ...)
346
347 SIDE EFFECT: For each file specified, _\bd_\bs_\bk_\bo_\bu_\bt assumes
348 the list named filenameFNS (i.e., the
349 file name, excluding extension, con-
350 catenated with _\bf_\bn_\bs ) contains a list
351 of function names, etc., to be loaded Any
352 previous version of the file will be
353 renamed to have extension ".back".
354
355(dskouts s_file1 ...)
356
357 SIDE EFFECT: applies _\bd_\bs_\bk_\bo_\bu_\bt to and prints the name of
358 each s_filei (with no additional
359 arguments, assuming filenameFNS to be a
360 list to be loaded) for which s_file_\bi is
361 either not in _\bf_\bi_\bl_\be_\bl_\bs_\bt (meaning it is a
362 new file not previously declared by _\bf_\bi_\bl_\be
363 or given as an argument to _\bd_\bs_\bk_\bi_\bn,
364 _\bd_\bs_\bk_\bo_\bu_\bt_\bs, or _\bd_\bs_\bk_\bo_\bu_\bt_\bs) or is in _\bf_\bi_\bl_\be_\bl_\bs_\bt and
365 has some recorded changes to definitions
366 of atoms in filenameFNS, as recorded by
367 _\bm_\ba_\br_\bk!_\bc_\bh_\ba_\bn_\bg_\be_\bd and noted by changes. If
368 _\bf_\bi_\bl_\bei is not specified, _\bf_\bi_\bl_\be_\bl_\bs_\bt will be
369 used. This is the most common way of
370 using dskouts. Typing (_\bd_\bs_\bk_\bo_\bu_\bt_\bs) will
371 save every file reported by (_\bc_\bh_\ba_\bn_\bg_\be_\bs)
372 to have changed definitions.
373
374
375(dv s_atom g_value)
376
377 EQUIVALENT TO: (_\bs_\be_\bt_\bq _\ba_\bt_\bo_\bm '_\bv_\ba_\bl_\bu_\be). _\bd_\bv calls
378 _\bm_\ba_\br_\bk!_\bc_\bh_\ba_\bn_\bg_\be_\bd.
379
380
381
382
383
384
385
386\e9
387
388\e9 Printed: July 21, 1983
389
390
391
392
393
394
395
396The CMU User Toplevel and the File Package 13-7
397
398
399(file 's_file)
400
401 SIDE EFFECT: declares its argument to be a file to be
402 used for reporting and saving changes to
403 functions by adding the file name to a
404 list of files, _\bf_\bi_\bl_\be_\bl_\bs_\bt. _\bf_\bi_\bl_\be is called
405 for each file argument of _\bd_\bs_\bk_\bi_\bn, _\bd_\bs_\bk_\bo_\bu_\bt,
406 and _\bd_\bs_\bk_\bo_\bu_\bt_\bs.
407
408(file-fns 's_file)
409
410 RETURNS: the name of the fileFNS list for its file
411 argument s_file.
412
413(getdef 's_file ['s_i1 ...])
414
415 SIDE EFFECT: selectively executes definitions for atoms
416 s_i1 ... from the specified file. Any of
417 the words to be defined which end with "@"
418 will be treated as patterns in which the @
419 matchs any suffix (just like the editor).
420 _\bg_\be_\bt_\bd_\be_\bf is driven by _\bg_\be_\bt_\bd_\be_\bf_\bt_\ba_\bb_\bl_\be (and thus
421 may be programmed). It looks for lines in
422 the file that start with a word in the
423 table. The first character must be a "("
424 or "[" followed by the word, followed by a
425 space, return or something else that will
426 not be considered as part of the identif-
427 ier by _\br_\be_\ba_\bd, e.g., "(" is unacceptable.
428 When one is found the next word is read.
429 If it matches one of the identifiers in
430 the call to _\bg_\be_\bt_\bd_\be_\bf then the table entry is
431 executed. The table entry is a function
432 of the expression starting in this line.
433 Output from _\bd_\bs_\bk_\bo_\bu_\bt is in acceptable format
434 for _\bg_\be_\bt_\bd_\be_\bf. _\bg_\be_\bt_\bd_\be_\bf
435
436 RETURNS: a list of the words which match the ones it
437 looked for, for which it found (but, depending
438 on the table, perhaps did not execute) in the
439 file.
440
441 NOTE: _\bg_\be_\bt_\bd_\be_\bf_\bt_\ba_\bb_\bl_\be is the table that drives _\bg_\be_\bt_\bd_\be_\bf. It
442 is in the form of an association list. Each ele-
443 ment is a dotted pair consisting of the name of a
444 function for which _\bg_\be_\bt_\bd_\be_\bf searches and a function
445 of one argument to be executed when it is found.
446
447
448
449
450
451\e9
452
453\e9 Printed: July 21, 1983
454
455
456
457
458
459
460
461The CMU User Toplevel and the File Package 13-8
462
463
464(mark!changed 's_f)
465
466 SIDE EFFECT: records the fact that the definition of
467 s_f has been changed. It is automatically
468 called by _\bd_\be_\bf, _\bd_\be_\bf_\bu_\bn, _\bd_\be, _\bd_\bf, _\bd_\be_\bf_\bp_\br_\bo_\bp, _\bd_\bm,
469 _\bd_\bv, and the editor when a definition is
470 altered.
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516\e9
517
518\e9 Printed: July 21, 1983
519
520
521