This chapter details Scheme 48’s command processor, which incorporates both a read-eval-print loop and an interactive debugger. At the > prompt, you can type either a Scheme form (expression or definition) or a command beginning with a comma. In inspection mode (see section 3.7) the prompt changes to : and commands no longer need to be preceded by a comma; input beginning with a letter or digit is assumed to be a command, not an expression. In inspection mode the command processor prints out a menu of selectable components for the current object of interest.
The command processor keeps track of a current focus value. This value is normally the last value returned by a command. If a command returns multiple values the focus object is a list of the values. The focus value is not changed if a command returns no values or a distinguished ‘unspecific’ value. Examples of forms that return this unspecific value are definitions, uses of set!, and (if #f 0). It prints as #{Unspecific}.
The reader used by the command processor reads ## as a special expression that evaluates to the current focus object.
> (list 'a 'b) '(a b) > (car ##) 'a > (symbol->string ##) "a" > (if #f 0) #{Unspecific} > ## "a" >
If an error, keyboard interrupt, or other breakpoint occurs, or the ,push command is used, the command processor invokes a recursive copy of itself, preserving the dynamic state of the program when the breakpoint occured. The recursive invocation creates a new command level. The command levels form a stack with the current level at the top. The command prompt indicates the number of stopped levels below the current one: > or : for the base level and n> or n: for all other levels, where n is the command-level nesting depth. The levels setting described below can be used to disable the automatic pushing of new levels.
The command processor’s evaluation package and the value of the current focus value are local to each command level. They are preserved when a new level is pushed and restored when it is discarded. The settings of all other settings are shared by all command levels.
Whenever moving to an existing level, either by sending an 〈eof〉 or by using ,reset or the other commands listed above, the command processor runs all of the dynamic-wind “after” thunks belonging to stopped computations on the discarded level(s).
There are many commands related to modules. Only the most commonly used module commands are described here; documentation for the rest can be found in section 4.8. There is also a brief description of modules, structures, and packages in section 2.6 below.
,config ,load filename
to load a file containing module definitions. If no command is given, the config package becomes the execution package for future commands.
If the current focus object is a continuation or a thread, then that continuation or thread’s stack is displayed.
Otherwise, if the current command level was initiated because of a breakpoint in the next level down, then the stack at that breakpoint is displayed.
Otherwise, there is no stack to display and a message is printed to that effect.
One line is printed out for each continuation on the chosen stack, going from top to bottom.
There are a number of settings that control the behavior of the command processor; most of them are booleans. They can be set using the ,set and ,unset commands.
The settings are as follows:
a longer prompt
retention of the continuation in effect at the point of errors
confusion among some newcomers
With levels disabled one must issue a ,push command immediately following an error in order to retain the error continuation for debugging purposes; otherwise the continuation is lost as soon as the focus object changes. If you don’t know anything about the available debugging tools, then levels might as well be disabled.
> ,set ask-before-loading will ask before loading modules > ,open random Load structure random (y/n)? y >
> ,set load-noisily will notify when loading modules and files > ,open random [random /usr/local/lib/scheme48/big/random.scm] >
There is a data inspector available via the ,inspect and ,debug commands. The inspector is particularly useful with procedures, continuations, and records. The command processor can be taken out of inspection mode by using the q command. When in inspection mode, input that begins with a letter or digit is read as a command, not as an expression. To see the value of a variable or number, do (begin exp) or use the ,run exp command.
In inspection mode the command processor prints out a menu of selectable components for the current focus object. To inspect a particular component, just type the corresponding number in the menu. That component becomes the new focus object. For example:
> ,inspect '(a (b c) d) (a (b c) d) [0] a [1] (b c) [2] d : 1 (b c) [0] b [1] c :
When a new focus object is selected the previous one is pushed onto a stack. You can pop the stack, reverting to the previous object, with the u command, or use the stack command to move to an earlier object.
Commands useful when in inspection mode:
u (up) pop object stack
m (more) print more of a long menu
(...) evaluate a form and select result
q quit
template select a closure or continuation’s template (Templates are the static components of procedures; these are found inside of procedures and continuations, and contain the quoted constants and top-level variables referred to by byte-compiled code.)
d (down) move to the next continuation (current object must be a continuation)
menu print the selection menu for the focus object
Multiple selection commands (u, d, and menu indexes) may be put on a single line.
All ordinary commands are available when in inspection mode. Similarly, the inspection commands can be used when not in inspection mode. For example:
> (list 'a '(b c) 'd) '(a (b c) d) > ,1 '(b c) > ,menu [0] b [1] c >
If the current command level was initiated because of a breakpoint in the next level down, then ,debug will invoke the inspector on the continuation at the point of the error. The u and d (up and down) commands then make the inspected-value stack look like a conventional stack debugger, with continuations playing the role of stack frames. D goes to older or deeper continuations (frames), and u goes back up to more recent ones.
The exec package contains procedures that are used to execute the command processor’s commands. A command ,foo is executed by applying the value of the identifier foo in the exec package to the (suitably parsed) command arguments.
,exec ,load filename
to load a file containing commands. If no command is given, the exec package becomes the execution package for future commands.
The required argument types are as follows:
filenames should be strings
other names and identifiers should be symbols
expressions should be s-expressions
commands (as for ,config and ,exec itself) should be lists of the form (command-name argument ...) where command-name is a symbol.
For example, the following two commands are equivalent:
,config ,load my-file.scm ,exec (config '(load "my-file.scm"))
The file scheme/vm/load-vm.scm in the source directory contains an example of an exec program.
If no-warnings appears as an option after the file name, no warnings about undefined external bindings (see Section 8.2) will be printed upon resuming the image. This is useful when the definitions of external bindings appear in shared objects that are only loaded after the resumption of the image.
Doing ,flush before building an image will reduce the amount of debugging information in the image, making for a smaller image file, but if an error occurs, the error message may be less helpful. Doing ,flush source maps before loading any programs used in the image will make it still smaller. See section 3.10 for more information.
.
maps - environment maps (local variable names, for inspector)
source - source code for continuations (displayed by inspector)
names - procedure names (as displayed by write and in error messages)
files - source file names
These commands refer to future compilations only, not to procedures that already exist. To have any effect, they must be done before programs are loaded. The default is to keep all four types.
Each command level has its own set of threads. These threads are suspended when a new level is entered and resumed when the owning level again becomes the current level. A thread that raises an error is not resumed unless explicitly restarted using the ,proceed command. In addition to any threads spawned by the user, each level has a thread that runs the command processor on that level. A new command-processor thread is started if the current one dies or is terminated. When a command level is abandoned for a lower level, or when a level is restarted using ,reset, all of the threads on that level are terminated and any dynamic-wind “after” thunks are run.
The following commands are useful when debugging multithreaded programs:
,translate /usr/gjc/ /zu/gjc/
will cause (load "/usr/gjc/foo.scm") to have the same effect as (load "/zu/gjc/foo.scm").