[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
`lazy-catch' and `dynamic-wind'
From: |
Ludovic Courtès |
Subject: |
`lazy-catch' and `dynamic-wind' |
Date: |
Sun, 23 Nov 2008 18:25:42 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) |
Hello Guilers!
I noticed the following subtle difference between fluids and SRFI-39
parameters when accessed from a `lazy-catch' handler:
(define fl (make-fluid))
(fluid-set! fl 'outside)
(lazy-catch #t
(lambda ()
(fluid-set! fl 'inside)
(throw 'foobar))
(lambda (key . args)
(format #t "fluid = ~A~%" (fluid-ref fl))
(exit 1)))
=> PRINTS: fluid = inside
... compared to:
(use-modules (srfi srfi-39))
(define fl (make-parameter 'outside))
(lazy-catch #t
(lambda ()
(parameterize ((fl 'inside))
(throw 'foobar)))
(lambda (key . args)
(format #t "fluid = ~A~%" (fl))
(exit 1)))
=> PRINTS: fluid = outside
This comes from the fact that `parameterize' sets up a `dynamic-wind'
whose unwinder is called *before* the `lazy-catch' handler. I find it a
bit counter-intuitive since the `lazy-catch' is documented as follows:
This behaves exactly like `catch', except that it does not unwind
the stack before invoking HANDLER.
The stack is indeed not unwinded, but the unwinders have already been
invoked, as illustrated here:
(lazy-catch #t
(lambda ()
(dynamic-wind
(lambda () #t)
(lambda () (throw 'foobar))
(lambda () (format #t "unwind~%"))))
(lambda (key . args)
(let ((stack (make-stack #t)))
(display-backtrace stack (current-output-port)))))
=> PRINTS:
unwind
[...]
30: 5* [gsubr-apply #<primitive-procedure throw> foobar]
In unknown file:
?: 6* [#<procedure #f (key . args)> foobar]
In ../../src/lazy-catch+fluid.scm:
33: 7* (let* ((stack #)) (display-backtrace stack (current-output-port)))
Am I missing something or should we consider it a bug?
Thanks,
Ludo'.
- `lazy-catch' and `dynamic-wind',
Ludovic Courtès <=