Previous: , Up: syntaxes   [Contents][Index]


5.4 Capturing the current dynamic environment

Syntax: with-current-dynamic-environment ?exception-retvals-maker ?thunk

Build and return a thunk that, wherever it is called, evaluates ?thunk in the dynamic environment of the macro use and returns its return values. If ?thunk raises an exception: apply the procedure ?exception-retvals-maker to the raised object and return its return values.

Exceptions raised by ?exception-retvals-maker are not blocked.

Usage examples:

(import (only (vicare checks)
              with-result
              add-result))

(define parm
  (make-parameter #f))

(with-result
  (parameterise ((parm 'outer))
    (let* ((counter 0)
           (thunk   (parameterise ((parm 'inner))
                      (with-current-dynamic-environment
                          values
                        (lambda ()
                          (set! counter (+ 1 counter))
                          (add-result (list 'inside-thunk (parm))))))))
      (add-result (parm))
      (add-result 'calling-thunk-1)
      (thunk)
      (add-result 'calling-thunk-2)
      (thunk)
      counter)))
⇒ (2 (outer
       calling-thunk-1 (inside-thunk inner)
       calling-thunk-2 (inside-thunk inner)))

(with-result
  (parameterise ((parm 'outer))
    (let* ((counter 0)
           (thunk   (parameterise ((parm 'inner))
                      (with-current-dynamic-environment
                          values
                        (lambda ()
                          (set! counter (+ 1 counter))
                          (add-result (list 'inside-thunk (parm)))
                          (add-result 'raise-exception)
                          (raise 123))))))
      (add-result (parm))
      (add-result 'calling-thunk-1)
      (let ((A (thunk)))
        (add-result 'calling-thunk-2)
        (let ((B (thunk)))
          (values A B counter))))))
⇒ (123 123 2
    (outer
     calling-thunk-1 (inside-thunk inner) raise-exception
     calling-thunk-2 (inside-thunk inner) raise-exception))

Previous: , Up: syntaxes   [Contents][Index]

This document describes version 0.1.0-devel.1 of MMCK Exceptional Conditions.