(guile.info.gz) Dynamic Roots
32.3 Dynamic Roots
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
In a thread-based system, each thread has its own dynamic root.
Therefore, continuations created by one thread may not be invoked by
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.
-- Scheme Procedure: call-with-dynamic-root thunk handler
-- C Function: scm_call_with_dynamic_root (thunk, handler)
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 `throw' would. If this happens,
HANDLER is called outside the scope of the new root - it is called
in the same dynamic context in which `call-with-dynamic-root' was
If THUNK captures a continuation, the continuation is rooted at
the call to THUNK. In particular, the call to
`call-with-dynamic-root' is not captured. Therefore,
`call-with-dynamic-root' always returns at most one time.
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:
(lambda (errcode) errcode))))
The problem is, on what port will `fnord' be displayed? You might
expect that because of the `with-output-to-port' that it will be
displayed on the port bound to `some-port'. But it probably won't
- before evaluating the thunk, dynamic winds are unwound,
including those created by `with-output-to-port'. So, the
standard output port will have been re-set to its default value
before `display' is evaluated.
(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.)
-- Scheme Procedure: dynamic-root
-- C Function: scm_dynamic_root ()
Return an object representing the current dynamic root.
These objects are only useful for comparison using `eq?'. They
are currently represented as numbers, but your code should in no
way depend on this.
-- Scheme Procedure: quit [exit_val]
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
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.
-- Scheme Procedure: batch-mode?
Returns a boolean indicating whether the interpreter is in batch
-- Scheme Procedure: set-batch-mode?! arg
If ARG is true, switches the interpreter to batch mode. The `#f'
case has not been implemented.
automatically generated byinfo2html