BSD 4_3 development
[unix-history] / usr / lib / lisp / manual / chc.r
APPENDIX C
Short Subjects.
The Garbage Collector
The garbage collector is invoked automatically whenever
a collectable data type runs out. All data types are col-
lectable except strings and atoms are not. After a garbage
collection finishes, the collector will call the function
_\bg_\bc_\ba_\bf_\bt_\be_\br which should be a lambda of one argument. The argu-
ment passed to _\bg_\bc_\ba_\bf_\bt_\be_\br is the name of the data type which
ran out and caused the garbage collection. It is _\bg_\bc_\ba_\bf_\bt_\be_\br's
responsibility to allocate more pages of free space. The
default _\bg_\bc_\ba_\bf_\bt_\be_\br makes its decision based on the percentage
of space still in use after the garbage collection. If
there is a large percentage of space still in use, _\bg_\bc_\ba_\bf_\bt_\be_\br
allocates a larger amount of free space than if only a small
percentage of space is still in use. The default _\bg_\bc_\ba_\bf_\bt_\be_\br
will also print a summary of the space in use if the vari-
able $_\bg_\bc_\bp_\br_\bi_\bn_\bt is non nil. The summary always includes the
state of the list and fixnum space and will include another
type if it caused the garbage collection. The type which
caused the garbage collection is preceded by an asterisk.
Debugging
There are two simple functions to help you debug your
programs: _\bb_\ba_\bk_\bt_\br_\ba_\bc_\be and _\bs_\bh_\bo_\bw_\bs_\bt_\ba_\bc_\bk. When an error occurs (or
when you type the interrupt character), you will be left at
a break level with the state of the computation frozen in
the stack. At this point, calling the function _\bs_\bh_\bo_\bw_\bs_\bt_\ba_\bc_\bk
will cause the contents of the lisp evaluation stack to be
printed in reverse chronological order (most recent first).
When the programs you are running are interpreted or traced,
the output of _\bs_\bh_\bo_\bw_\bs_\bt_\ba_\bc_\bk can be very verbose. The function
_\bb_\ba_\bk_\bt_\br_\ba_\bc_\be prints a summary of what _\bs_\bh_\bo_\bw_\bs_\bt_\ba_\bc_\bk prints. That
is, if showstack would print a list, _\bb_\ba_\bk_\bt_\br_\ba_\bc_\be would only
print the first element of the list. If you are running
compiled code with the (_\bs_\bt_\ba_\bt_\bu_\bs _\bt_\br_\ba_\bn_\bs_\bl_\bi_\bn_\bk) non nil, then fast
links are being made. In this case, there is not enough
information on the stack for _\bs_\bh_\bo_\bw_\bs_\bt_\ba_\bc_\bk and _\bb_\ba_\bk_\bt_\br_\ba_\bc_\be. Thus,
if you are debugging compiled code you should probably do
(_\bs_\bs_\bt_\ba_\bt_\bu_\bs _\bt_\br_\ba_\bn_\bs_\bl_\bi_\bn_\bk _\bn_\bi_\bl).
\e9
\e9 C-1
C-2
If the contents of the stack don't tell you enough
about your problem, the next thing you may want to try is to
run your program with certain functions traced. You can
direct the trace package to stop program execution when it
enters a function, allowing you to examine the contents of
variables or call other functions. The trace package is
documented in Chapter 11.
It is also possible to single step the evaluator and to
look at stack frames within lisp. The programs which per-
form these actions are described in Chapters 14 and 15.
\e9
\e9 Printed: July 21, 1983
C-3
The Interpreter's Top Level
The default top level interpreter for Franz, named
_\bf_\br_\ba_\bn_\bz-_\bt_\bo_\bp-_\bl_\be_\bv_\be_\bl is defined in /usr/lib/lisp/toplevel.l It is
given control when the lisp system starts up because the
variable top-level is bound to the symbol _\bf_\br_\ba_\bn_\bz-_\bt_\bo_\bp-_\bl_\be_\bv_\be_\bl.
The first action _\bf_\br_\ba_\bn_\bz-_\bt_\bo_\bp-_\bl_\be_\bv_\be_\bl takes is to print out the
name of the current version of the lisp system. Then it
loads the file .lisprc from the HOME directory of the person
invoking the lisp system if that file exists. The .lisprc
file allows you to set up your own defaults, read in files,
set up autoloading or anything else you might want to do to
personalize the lisp system. Next, the top level goes into
a prompt-read-eval-print loop. Each time around the loop,
before printing the prompt it checks if the variable user-
top-level is bound. If so, then the value of user-top-level
will be _\bf_\bu_\bn_\bc_\ba_\bl_\bled. This provides a convenient way for a
user to introduce his own top level (Liszt, the lisp com-
piler, is an example of a program which uses this). If the
user types a ^D (which is the end of file character), and
the standard input is not from a keyboard, the lisp system
will exit. If the standard input is a keyboard and if the
value of (_\bs_\bt_\ba_\bt_\bu_\bs _\bi_\bg_\bn_\bo_\br_\be_\be_\bo_\bf) is nil, the lisp system will
also exit. Otherwise the end of file will be ignored. When
a _\br_\be_\bs_\be_\bt is done the current value of _\be_\br_\br_\bl_\bi_\bs_\bt is saved away
and control is thrown back up to the top level where _\be_\bv_\ba_\bl is
mapped over the saved value of _\be_\br_\br_\bl_\bi_\bs_\bt.
\e9
\e9 Printed: July 21, 1983