new copyright; att/bsd/shared
[unix-history] / usr / src / old / lisp / PSD.doc / ch6.n
CommitLineData
3edcb7c8
KB
1.\" Copyright (c) 1980 The Regents of the University of California.
2.\" All rights reserved.
e105ea67 3.\"
3edcb7c8
KB
4.\" %sccs.include.redist.roff%
5.\"
6.\" @(#)ch6.n 6.2 (Berkeley) %G%
e105ea67 7.\"
c2858780
NC
8." $Header: ch6.n,v 1.4 83/07/21 21:08:16 sklower Exp $
9.Lc System\ Functions 6
10.pp
11This chapter describes the functions used to interact
12with internal components of the Lisp system and operating system.
13.Lf allocate "'s_type 'x_pages"
14.Wh
15s_type is one of the
16.Fr
17data types described in \(sc1.3.
18.Re
19x_pages.
20.Se
21.Fr
22attempts to allocate x_pages of type s_type.
23If there aren't x_pages of memory left, no space will be
24allocated and an error will occur.
25The storage that is allocated is not given to the caller, instead it is
26added to the free storage list of s_type.
27The functions
28.i segment
29and
30.i small-segment
31allocate blocks of storage and return it to the caller.
32.Lf argv "'x_argnumb"
33.Re
34a symbol whose pname is the x_argnumb\fIth\fP argument (starting at 0)
35on the command
36line which invoked the current lisp.
37.No
38if x_argnumb is less than zero, a fixnum whose value is the number of arguments
39on the command line is returned.
40\fI(argv\ 0)\fP returns the name of the lisp you are running.
41.Lf baktrace
42.Re
43nil
44.Se
45the lisp runtime stack is examined and the name of (most) of the functions
46currently in execution are printed, most active first.
47.No
48this will occasionally miss the names of compiled lisp functions due to
49incomplete information on the stack.
50If you are tracing compiled code, then \fIbaktrace\fP won't be able
51to interpret the stack unless
52.i (sstatus\ translink\ nil)
53was done.
54See the function
55.i showstack
56for another way of printing the lisp runtime
57stack.
58This misspelling is from Maclisp.
59.Lf chdir "'s_path"
60.Re
61t iff the system call succeeds.
62.Se
63the current directory set to s_path.
64Among other things, this will affect the default location
65where the input/output functions look for and create files.
66.No
67\fIchdir\fP follows the standard UNIX conventions, if s_path does not begin
68with a slash, the default path is changed to the current path with
69s_path appended.
70.i Chdir
71employs tilde-expansion (discussed in Chapter 5).
72.Lf command-line-args
73.Re
74a list of the arguments typed on the command line, either to the
75lisp interpreter, or saved lisp dump, or application compiled
76with the autorun option (liszt -r).
77.Lf deref "'x_addr"
78.Re
79The contents of x_addr, when thought of as a longword memory
80location.
81.No
82This may be useful in constructing arguments to C functions
83out of `dangerous' areas of memory.
84.Lf dumplisp "s_name"
85.Re
86nil
87.Se
88the current lisp is dumped to the named file.
89When s_name is executed, you will be in a lisp in the
90same state as when the dumplisp was done.
91.No
92dumplisp will fail if one tries to
93write over the current running file.
94UNIX does not allow you to modify the file you are running.
95.Lf eval-when "l_time g_exp1 ..."
96.Se
97l_time may contain any combination of the symbols
98.i load ,
99.i eval ,
100and
101.i compile .
102The effects of load and compile is discussed in \(sc12.3.2.1
103compiler.
104If eval is present however, this simply means that the expressions g_exp1
105and so on are evaluated from left to right.
106If eval is not present, the forms are not evaluated.
107.Lf exit "['x_code]"
108.Re
109nothing (it never returns).
110.Se
111the lisp system dies with exit code x_code or 0 if x_code is not
112specified.
113.Lf fake "'x_addr"
114.Re
115the lisp object at address x_addr.
116.No
117This is intended to be used by people debugging the lisp system.
118.Lf fork
119.Re
120nil to the child process and the process number of the child to
121the parent.
122.Se
123A copy of the current lisp system is made in memory and both
124lisp systems now begin to run.
125This function can be used interactively to temporarily
126save the state of Lisp (as shown below), but you must be careful that only one
127of the lisp's interacts with the terminal after the fork.
128The
129.i wait
130function is useful for this.
131.Eb
132\-> \fI(setq foo 'bar)\fP ;; set a variable
133bar
134\-> \fI(cond ((fork)(wait)))\fP ;; duplicate the lisp system and
135nil ;; make the parent wait
136\-> \fIfoo\fP ;; check the value of the variable
137bar
138\-> \fI(setq foo 'baz)\fP ;; give it a new value
139baz
140\-> \fIfoo\fP ;; make sure it worked
141baz
142\-> \fI(exit)\fP ;; exit the child
143(5274 . 0) ;; the \fIwait\fP function returns this
144\-> \fIfoo\fP ;; we check to make sure parent was
145bar ;; not modified.
146.Ee
147.Lf gc
148.Re
149nil
150.Se
151this causes a garbage collection.
152.No
153The function
154.i gcafter
155is not called automatically after this function finishes.
156Normally the user doesn't have to call
157.i gc
158since
159garbage collection occurs automatically whenever internal free lists
160are exhausted.
161.Lf gcafter "s_type"
162.Wh
163s_type is one of the
164.Fr
165data types listed in \(sc1.3.
166.No
167this function is called by the garbage collector
168after a garbage collection which was caused by running out of
169data type s_type.
170This function should determine if more space need be allocated
171and if so should allocate it.
172There is a default gcafter function but users who want control over
173space allocation can define their own -- but note that it must be
174an nlambda.
175.Lf getenv "'s_name"
176.Re
177a symbol whose pname is the value of s_name in the current
178UNIX environment.
179If s_name doesn't exist in the current environment, a symbol with a null pname
180is returned.
181.Lf hashtabstat
182.Re
183a list of fixnums representing the number of symbols in each bucket of
184the oblist.
185.No
186the oblist is stored a hash table of buckets.
187Ideally there would be the same number of symbols in each bucket.
188.Lf help "[sx_arg]"
189.Se
190If sx_arg is a symbol then
191the portion of this manual beginning with the description of sx_arg
192is printed on the terminal.
193If sx_arg is a fixnum or the name of one of the appendicies, that
194chapter or appendix is printed on the terminal.
195If no argument is provided,
196.i help
197prints the options that it recognizes.
198The program `more' is used to print the manual on the terminal; it will
199stop after each page and will continue after the space key is pressed.
200.Lf include "s_filename"
201.Re
202nil
203.Se
204The given filename is
205.i load ed
206into the lisp.
207.No
208this is similar to load except the argument is not evaluated.
209Include means something special to the compiler.
210.Lf include-if "'g_predicate s_filename"
211.Re
212nil
213.Se
214This has the same effect as include, but is only actuated
215if the predicate is non-nil.
216.Lf includef "'s_filename"
217.Re
218nil
219.Se
220this is the same as
221.i include
222except the argument is evaluated.
223.Lf includef-if "'g_predicate s_filename"
224.Re
225nil
226.Se
227This has the same effect as includef, but is only actuated
228if the predicate is non-nil.
229.Lf maknum "'g_arg"
230.Re
231the address of its argument converted into a fixnum.
232.Lf monitor "['xs_maxaddr]"
233.Re
234t
235.Se
236If xs_maxaddr is t then profiling of the entire lisp system is begun.
237If xs_maxaddr is a fixnum then profiling is done only up to address
238xs_maxaddr.
239If xs_maxaddr is not given, then profiling is stopped and the data
240obtained is written to the file 'mon.out' where it can be analyzed
241with the UNIX 'prof' program.
242.No
243this function only works if the lisp system has been compiled
244in a special way, otherwise, an error is invoked.
245.Lf opval "'s_arg ['g_newval]"
246.Re
247the value associated with s_arg before the call.
248.Se
249If g_newval is specified, the value associated with s_arg is changed to
250g_newval.
251.No
252\fIopval\fP keeps track of storage allocation. If s_arg is one of the data types
253then \fIopval\fP will return a list of three fixnums representing the number of
254items of that type in use, the number of pages allocated and the number
255of items of that type per page.
256You should never try to change the value \fIopval\fP associates
257with a data type using
258\fIopval\fP.
259.br
260If s_arg is
261.i pagelimit
262then
263.i opval
264will return (and set if g_newval is given)
265the maximum amount of lisp data pages
266it will allocate.
267This limit should remain small unless you know your program requires
268lots of space as this limit will catch programs in infinite loops which
269gobble up memory.
270.Lf *process "'st_command ['g_readp ['g_writep]]"
271.Re
272either a fixnum if one argument is given, or a list of two ports and a
273fixnum if two or three arguments are given.
274.No
275\fI*process\fP starts another process by passing st_command to the shell
276(it first tries /bin/csh, then it tries /bin/sh if /bin/csh doesn't exist).
277If only one argument is given to \fI*process\fP,
278\fI*process\fP waits for the new
279process to die and then returns the exit code of the new process.
280If more two or three arguments are given, \fI*process\fP starts the process
281and then returns a list which, depending on the value of g_readp
282and g_writep, may contain i/o ports for communcating with the new
283process.
284If g_writep is non-null, then a port will be created which the lisp program
285can use to send characters to the new process.
286If g_readp is non-null, then a port will be created which the lisp program
287can use to read characters from the new process.
288The value returned by \fI*process\fP is (readport\ writeport\ pid)
289where readport and writeport are either nil or a port based on the value
290of g_readp and g_writep. Pid is the process id of the new process.
291Since it is hard to remember the order of g_readp and g_writep, the
292functions \fI*process-send\fP and \fI*process-receive\fP were written to
293perform the common functions.
294.Lf *process-receive "'st_command"
295.Re
296a port which can be read.
297.Se
298The command st_command is given to the shell and it is started running in the
299background.
300The output of that command is available for reading via the port returned.
301The input of the command process is set to /dev/null.
302.Lf *process-send "'st_command"
303.Re
304a port which can be written to.
305.Se
306The command st_command is given to the shell and it is started runing in the
307background.
308The lisp program can provide input for that command
309by sending characters to the port returned by this function.
310The output of the command process is set to /dev/null.
311.Lf process "s_pgrm [s_frompipe s_topipe]"
312.Re
313if the optional arguments are
314not present a fixnum which is the exit code when s_prgm dies.
315If the optional arguments are present, it returns a fixnum which
316is the process id of the child.
317.No
318This command is obsolete.
319New programs should use one of the \fI*process\fP commands
320given above.
321.Se
322If s_frompipe and s_topipe are given, they are bound to
323ports which are pipes which
324direct characters from
325.Fr
326to the new process
327and to
328.Fr
329from the new process respectively.
330.i Process
331forks a process named s_prgm and waits for it to die iff there
332are no pipe arguments given.
333.Lf ptime
334.Re
335a list of two elements.
336The first is the amount of processor time used
337by the lisp system so far, and the
338second is the amount of time used by the garbage collector so far.
339.No
340the time is measured in those units used by the
341.i times (2)
342system call, usually 60\fIth\fPs of a second.
343The first number includes the second number.
344The amount of time used by garbage collection is not recorded
345until the first call to ptime.
346This is done to prevent overhead when the user is not interested in
347garbage collection times.
348.Lf reset
349.Se
350the lisp runtime stack is cleared and the system restarts at the top level
351by executing a \fI(funcall\ top-level\ nil)\fP.
352.Lf restorelisp "'s_name"
353.Se
354this reads in file s_name (which was created by
355.i savelisp )
356and then does a \fI(reset)\fP.
357.No
358This is only used on VMS systems where
359.i dumplisp
360cannot be used.
361.Lf retbrk "['x_level]
362.Wh
363x_level is a small integer of either sign.
364.Se
365The default error handler keeps a notion of the current level
366of the error caught. If x_level is negative, control is thrown
367to this default error handler whose level is that many less than
368the present, or to \fItop-level\fP if there aren't enough.
369If x_level is non-negative, control is passed to the handler at
370that level. If x_level is not present, the value -1 is taken by
371default.
372.Lf *rset "'g_flag"
373.Re
374g_flag
375.Se
376If g_flag is non nil then the lisp system will maintain extra information
377about calls to \fIeval\fP and \fIfuncall\fP.
378This record keeping slows down the evaluation but this is
379required for the functions
380\fIevalhook\fP, \fIfuncallhook\fP, and \fIevalframe\fP to work.
381To debug compiled lisp code the transfer tables should be unlinked:
382\fI(sstatus\ translink\ nil)\fP
383.Lf savelisp "'s_name"
384.Re
385t
386.Se
387the state of the Lisp system is saved in the file s_name.
388It can be read in by
389.i restorelisp .
390.No
391This is only used on VMS systems where
392.i dumplisp
393cannot be used.
394.Lf segment "'s_type 'x_size"
395.Wh
396s_type is one of the data types given in \(sc1.3
397.Re
398a segment of contiguous lispvals of type s_type.
399.No
400In reality,
401.i segment
402returns a new data cell of type s_type and allocates
403space for x_size \- 1 more s_type's beyond the one returned.
404.i Segment
405always allocates new space and does so in 512 byte chunks.
406If you ask for 2 fixnums, segment will actually allocate 128 of them
407thus wasting 126 fixnums.
408The function
409.i small-segment
410is a smarter space allocator and should be used whenever possible.
411.Lf shell
412.Re
413the exit code of the shell when it dies.
414.Se
415this forks a new shell and returns when the shell dies.
416.Lf showstack
417.Re
418nil
419.Se
420all forms currently in evaluation are printed, beginning with the most recent.
421For compiled code the most that
422showstack will show is the function name and it may miss
423some functions.
424.Lf signal "'x_signum 's_name"
425.Re
426nil if no previous call to signal has been made, or the previously
427installed s_name.
428.Se
429this declares that the function named s_name
430will handle the signal number x_signum.
431If s_name is nil, the signal is ignored. Presently only
432four UNIX signals are caught.
433They and their numbers are:
434Interrupt(2), Floating exception(8), Alarm(14), and
435Hang-up(1).
436.Lf sizeof "'g_arg"
437.Re
438the number of bytes required to store one object of type g_arg, encoded
439as a fixnum.
440.Lf small-segment "'s_type 'x_cells"
441.Wh
442s_type is one of fixnum, flonum and value.
443.Re
444a segment of x_cells data objects of type s_type.
445.Se
446This may call
447.i segment
448to allocate new space or it may be able to fill the request on a page
449already allocated.
450The value returned by
451.i small-segment
452is usually stored in the data subpart
453of an array object.
454.Lf sstatus "g_type g_val"
455.Re
456g_val
457.Se
458If g_type is not one of the special sstatus codes described in the
459next few pages
460this simply sets g_val as the value of status
461type g_type in the system status property list.
462.Lf sstatus\ appendmap "g_val"
463.Re
464g_val
465.Se
466If g_val is non-null when
467.i fasl
468is told to create a load map, it will append to the file name given in
469the
470.i fasl
471command, rather than creating a new map file.
472The initial value is nil.
473.Lf sstatus\ automatic-reset "g_val"
474.Re
475g_val
476.Se
477If g_val is non-null when an error occurs which no one wants to
478handle, a
479.i reset
480will be done instead of entering a primitive internal break loop.
481The initial value is t.
482.Lf sstatus\ chainatom "g_val"
483.Re
484g_val
485.Se
486If g_val is non nil and a
487.i car
488or
489.i cdr
490of a symbol is done, then nil will be returned instead of an error
491being signaled.
492This only affects the interpreter, not the compiler.
493The initial value is nil.
494.Lf sstatus\ dumpcore "g_val"
495.Re
496g_val
497.Se
498If g_val is nil,
499.Fr
500tells UNIX that a segmentation violation or
501bus error should cause a core dump.
502If g_val is non nil then
503.Fr
504will catch those errors and print a message advising the user to reset.
505.No
506The initial value for this flag is nil, and only those knowledgeable of
507the innards of the lisp system should ever set this flag non nil.
508.Lf sstatus\ dumpmode "x_val"
509.Re
510x_val
511.Se
512All subsequent
513.i dumplisp 's
514will be done in mode x_val.
515x_val may be either 413 or 410 (decimal).
516.No
517the advantage of mode 413 is that the dumped Lisp can be demand paged in when
518first started, which will make it start faster and disrupt other users less.
519The initial value is 413.
520.Lf sstatus\ evalhook "g_val"
521.Re
522g_val
523.Se
524When g_val is non nil, this enables the
525evalhook and funcallhook traps in the evaluator.
526See \(sc14.4 for more details.
527.Lf sstatus\ feature "g_val"
528.Re
529g_val
530.Se
531g_val is added to the \fI(status\ features)\fP list,
532.Lf sstatus\ gcstrings "g_val"
533.Re
534g_val
535.Se
536if g_val is non-null, and if string garbage collection was enabled when
537the lisp system was compiled, string space will be garbage collected.
538.No
539the default value for this is nil since in most applications garbage
540collecting strings is a waste of time.
541.Lf sstatus\ ignoreeof "g_val"
542.Re
543g_val
544.Se
545If g_val is non-null when
546an end of file (CNTL-D on UNIX) is typed to the standard top-level interpreter,
547it will be ignored rather then cause the lisp system to exit.
548If the the standard input is a file or pipe then this has no effect,
549an EOF will always cause lisp to exit.
550The initial value is nil.
551.Lf sstatus\ nofeature "g_val"
552.Re
553g_val
554.Se
555g_val is removed from the status features list if it was present.
556.Lf sstatus\ translink "g_val"
557.Re
558g_val
559.Se
560If g_val is nil then all transfer tables are cleared and further calls
561through the transfer table will not cause the fast links to be set up.
562If g_val is the symbol
563.i on
564then all possible transfer table entries will be linked and the flag
565will be set to cause fast links to be set up dynamically.
566Otherwise all that is done is to set the flag to cause fast links
567to be set up dynamically.
568The initial value is nil.
569.No
570For a discussion of transfer tables, see \(sc12.8.
571.Lf sstatus\ uctolc "g_val"
572.Re
573g_val
574.Se
575If g_val is not nil then all unescaped capital letters
576in symbols read by the reader will be converted to lower case.
577.No
578This allows
579.Fr
580to be compatible with single case lisp
581systems (e.g. Maclisp, Interlisp and UCILisp).
582.Lf status "g_code"
583.Re
584the value associated with the status code g_code
585if g_code is not one of the special cases given below
586.Lf status\ ctime
587.Re
588a symbol whose print name is the current time and date.
589.Ex
590\fI(status ctime)\fP = |Sun Jun 29 16:51:26 1980|
591.No
592This has been made obsolete by \fItime-string\fP, described below.
593.Lf status\ feature "g_val"
594.Re
595t iff g_val is in the status features list.
596.Lf status\ features
597.Re
598the value of the features code, which is a list of features which
599are present in this system.
600You add to this list with \fI(sstatus\ feature\ 'g_val)\fP
601and test if feature g_feat is present with \fI(status\ feature\ 'g_feat)\fP.
602.Lf status\ isatty
603.Re
604t iff the standard input is a terminal.
605.Lf status\ localtime
606.Re
607a list of fixnums representing the current time.
608.Ex
609\fI(status localtime)\fP = (3 51 13 31 6 81 5 211 1)
610.br
611means 3\fIrd\fP second, 51\fIst\fP minute, 13\fIth\fP hour (1 p.m),
61231\fIst\fP day, month 6 (0\ =\ January), year 81 (0\ =\ 1900),
613day of the week 5 (0\ =\ Sunday), 211\fIth\fP day of the year
614and daylight savings time is in effect.
615.Lf status\ syntax "s_char"
616.No
617This function should not be used.
618See the description of
619.i getsyntax
620(in Chapter 7) for a replacement.
621.Lf status\ undeffunc
622.Re
623a list of all functions which transfer table entries point to but which
624are not defined at this point.
625.No
626Some of the undefined functions listed could be arrays which have yet
627to be created.
628.Lf status\ version
629.Re
630a string which is the current lisp version name.
631.Ex
632\fI(status version)\fP = "Franz Lisp, Opus 38.61"
633.Lf syscall "'x_index ['xst_arg1 ...]"
634.Re
635the result of issuing the UNIX system call number x_index with arguments
636xst_arg\fIi\fP.
637.No
638The UNIX system calls are described in section 2 of the
639UNIX Programmer's manual.
640If xst_arg\fIi\fP is a fixnum, then
641its value is passed as an argument, if it is a symbol then
642its pname is passed and finally if it is a string then the string itself
643is passed as an argument.
644Some useful syscalls are:
645.br
646\fI(syscall\ 20)\fP returns process id.
647.br
648\fI(syscall\ 13)\fP returns the number of seconds since Jan 1, 1970.
649.br
650\fI(syscall\ 10\ 'foo)\fP will unlink (delete) the file foo.
651.Lf sys:access "'st_filename 'x_mode"
652.Lx sys:chmod "'st_filename 'x_mode"
653.Lx sys:gethostname
654.Lx sys:getpid
655.Lx sys:getpwnam 'st_username
656.Lx sys:link "'st_oldfilename 'st_newfilename"
657.Lx sys:time
658.Lx sys:unlink 'st_filename
659.No
660We have been warned that the actual system call numbers may vary
661among different UNIX systems. Users concerned about portability
662may wish to use this group of functions.
663Another advantage is that tilde-expansion is performed on
664all filename arguments.
665These functions do what is described
666in the system call section of your UNIX manual.
667.br
668.sp
669.i sys:getpwnam
670returns a vector of four entries from the password file, being
671the user name, user id, group id, and home directory.
672.Lf time-string "['x_seconds]"
673.Re
674an ascii string giving the time and date which was
675x_seconds after UNIX's idea of creation
676(Midnight, Jan 1, 1970 GMT). If no argument is given,
677time-string returns the current date.
678This supplants \fI(status ctime)\fP, and may be used
679to make the results of \fIfilestat\fP more intelligible.
680.Lf top-level
681.Re
682nothing (it never returns)
683.No
684This function is the top-level read-eval-print loop.
685It never returns any value.
686Its main utility is that if you redefine it, and do a (reset) then the
687redefined (top-level) is then invoked.
688The default top-level for Franz, allow one to specify
689his own printer or reader, by binding the symbols \fBtop-level-printer\fP
690and \fBtop-level-reader\fP.
691One can let the default top-level do most of the drudgery in catching
692.i reset 's,
693and reading in .lisprc files,
694by binding the symbol \fBuser-top-level\fP, to a routine that
695concerns itself only with the read-eval-print loop.
696.Lf wait
697.Re
698a dotted pair \fI(processid . status)\fP when the
699next child process dies.