From: ludo@gnu.org (Ludovic Courtès)
To: guile-user@gnu.org
Subject: `lazy-catch' and `dynamic-wind'
Date: Sun, 23 Nov 2008 18:25:42 +0100 [thread overview]
Message-ID: <87fxliicbt.fsf@gnu.org> (raw)
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'.
next reply other threads:[~2008-11-23 17:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-23 17:25 Ludovic Courtès [this message]
2008-11-23 21:34 ` `lazy-catch' and `dynamic-wind' Neil Jerram
2008-11-23 22:56 ` Ludovic Courtès
2008-11-23 23:25 ` Neil Jerram
2008-11-24 8:43 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fxliicbt.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).