unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* `lazy-catch' and `dynamic-wind'
@ 2008-11-23 17:25 Ludovic Courtès
  2008-11-23 21:34 ` Neil Jerram
  0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2008-11-23 17:25 UTC (permalink / raw)
  To: guile-user

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'.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-24  8:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-23 17:25 `lazy-catch' and `dynamic-wind' Ludovic Courtès
2008-11-23 21:34 ` 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

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).