(debug) -- that is, by invoking the debug
procedure with no arguments.
inspect procedure is installed at a particular point in a
program, the execution of the program is interrupted every time that point
is reached, and an application called the interactive inspector is invoked.
Exiting from the inspector restarts the interrupted computation from the
same point.
factorial
function looks like:
> (factorial 12) |(factorial 12) | (factorial 11) | |(factorial 10) | | (factorial 9) | | |(factorial 8) | | | (factorial 7) | | | |(factorial 6) | | | | (factorial 5) | | | | |(factorial 4) | | | | | (factorial 3) | | | |[10](factorial 2) | | | |[11](factorial 1) | | | |[12](factorial 0) | | | |[12]1 | | | |[11]1 | | | |[10]2 | | | | | 6 | | | | |24 | | | | 120 | | | |720 | | | 5040 | | |40320 | | 362880 | |3628800 | 39916800 |479001600 479001600 >The vertical bars and bracketed numbers indicate the depth of the run-time stack (the number of procedure calls that have been initiated but not yet completed).
To turn on tracing for a procedure, the programmer re-enters the definition
of the procedure, replacing the keyword define with
trace-define. To turn it off again, the programmer re-enters
the original definition. Tracing can be turned on or off independently for
any number of procedures.
(begin (warning f s) e)where f is a symbol identifying the warning point and s is a string offering advisory information. A typical instance might look like this:
(begin (warning 'extract "An empty list was encountered") 0)This would result in the printing of the line
Warning in extract: An empty list was encountered.Note that the program does not stop at warning points; it prints out the advisory and continues running without interruption.
break procedure rather than the warning
procedure:
(begin (break 'extract "An empty list was encountered") 0)When this expression is evaluated, Chez Scheme prints
Break in extract: An empty list was encountered.and fires up the interactive debugger.
Pressing <Control/C> in the middle of a computation has the same effect as a break point except that no advisory line is printed before the debugger is started.
debug>The debugger is extremely simple in design. There are only seven commands, each of which is a single letter:
? to print a list of the other six debugger commands, with
brief descriptions;
e to exit from the debugger and resume the computation at
the point where it was interrupted;
r (``reset'') to discard the interrupted computation and
generate a new prompt;
a (``abort'') to shut down the entire Chez Scheme system
(probably not what you want; don't do this unless you're really finished!);
n to start up a new, local copy of the interactive
interface (when you exit from this local copy, you'll be back in the
debugger, and the interrupted computation can still be resumed);
s to print statistics about Chez Scheme's use of memory,
running time, etc.; and
i to activate the ``interactive inspector.''
debug> i #<system continuation in break> :UCs are expected to know only three commands for the interactive inspector:
?, which displays a list of potentially applicable
commands;
help, which displays one paragraph of instructions on how
to use the inspector;
quit, which exits from the inspector, resuming either the
debugger or the interrupted program.
error procedure(debug) to enter the
interactive debugger to collect further information.The two-line error message produced when Chez Scheme detects an error looks like this (the diagnosis varies with the nature of the error, of course):
Error: variable frogs is not bound. Type (debug) to enter the debugger.Here are the ``diagnosis'' parts of some typical error messages and their usual causes:
attempt to apply non-procedure ...A programmer can also induce a run-time error by invoking the
The program tried to evaluate some expression that looks superficially like a procedure call, but the value of the first expression turned out not to be a procedure.incorrect number of arguments to #<procedure ...>
The program tried to call a procedure, but gave it either too few arguments or too many.variable ... is not bound
The program tried to evaluate a variable that was never defined or otherwise given a value. It may be a misspelling for some other variable.... is not an integer
The program tried to call some procedure that accepts only integer arguments, such asmoduloorgcd, but gave it a non-integer value.unexpected end-of-file on #<input port ...>
A file from which Chez Scheme was loading a program ended without terminating all of the syntactic constructs that it started. The likely causes are (1) a missing right parenthesis; (2) a missing double quotation mark at the end of a string literal -- note that a Scheme string literal can extend over more than one line; (3) a comment that accidently blocks out part of the syntactic structure of the program.invalid vector size request
The program tried to allocate a vector (array) of negative size.cannot read from #<closed input port ...>
The program tried to read from a file after closing it.
error procedure, which is analogous to the
warning and break procedures; evaluating the
expression
(error 'extract "An empty list was encountered")cuts off the computation and generates the error message
Error in extract: An empty list was encountered. Type (debug) to enter the debugger.followed by a new prompt.
inspect procedure, giving it
the value to be inspected as argument:
(inspect frog-tree)No advisory message is printed when this procedure is invoked; the next thing the user sees is the inspector prompt.
Workshop front door ... Running Chez Scheme ... Editing ... Scheme bibliography