Node:Dynamic Roots, Next:Threads, Previous:Asyncs, Up:Scheduling
A dynamic root is a root frame of Scheme evaluation. The top-level repl, for example, is an instance of a dynamic root.
Each dynamic root has its own chain of dynamic-wind information. Each has its own set of continuations, jump-buffers, and pending CATCH statements which are inaccessible from the dynamic scope of any other dynamic root.
In a thread-based system, each thread has its own dynamic root. Therefore, continuations created by one thread may not be invoked by another.
Even in a single-threaded system, it is sometimes useful to create a new dynamic root. For example, if you want to apply a procedure, but to not allow that procedure to capture the current continuation, calling the procedure under a new dynamic root will do the job.
call-with-dynamic-root thunk handler | Scheme Procedure |
scm_call_with_dynamic_root (thunk, handler) | C Function |
Evaluate (thunk) in a new dynamic context, returning its value.
If an error occurs during evaluation, apply handler to the
arguments to the throw, just as If thunk captures a continuation, the continuation is rooted at
the call to thunk. In particular, the call to
Before calling thunk, the dynamic-wind chain is un-wound back to
the root and a new chain started for thunk. Therefore, this call
may not do what you expect:
;; Almost certainly a bug: (with-output-to-port some-port (lambda () (call-with-dynamic-root (lambda () (display 'fnord) (newline)) (lambda (errcode) errcode)))) The problem is, on what port will (This function was added to Guile mostly to help calls to functions in C libraries that can not tolerate non-local exits or calls that return multiple times. If such functions call back to the interpreter, it should be under a new dynamic root.) |
dynamic-root | Scheme Procedure |
scm_dynamic_root () | C Function |
Return an object representing the current dynamic root.
These objects are only useful for comparison using |
quit [exit_val] | Scheme Procedure |
Throw back to the error handler of the current dynamic root.
If integer exit_val is specified and if Guile is being used stand-alone and if quit is called from the initial dynamic-root, exit_val becomes the exit status of the Guile process and the process exits. |
When Guile is run interactively, errors are caught from within the
read-eval-print loop. An error message will be printed and abort
called. A default set of signal handlers is installed, e.g., to allow
user interrupt of the interpreter.
It is possible to switch to a "batch mode", in which the interpreter will terminate after an error and in which all signals cause their default actions. Switching to batch mode causes any handlers installed from Scheme code to be removed. An example of where this is useful is after forking a new process intended to run non-interactively.
batch-mode? | Scheme Procedure |
Returns a boolean indicating whether the interpreter is in batch mode. |
set-batch-mode?! arg | Scheme Procedure |
If arg is true, switches the interpreter to batch mode.
The #f case has not been implemented.
|