guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `lazy-catch' and `dynamic-wind'


From: Neil Jerram
Subject: Re: `lazy-catch' and `dynamic-wind'
Date: Sun, 23 Nov 2008 21:34:05 +0000

2008/11/23 Ludovic Courtès <address@hidden>:
> 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

This is as expected.  Note that there is nothing like dynamic-wind
inside fluid-set!  Did you perhaps mean with-fluids instead?  If you
used with-fluids, I would expect the same behaviour as you've
described for parameterize.

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

That text is misleading and should be improved.  See the manual
section [1] for the whole story, which explains that it is actually
only the call stack that is not unwound.

[1] 
http://www.gnu.org/software/guile/manual/html_node/Lazy-Catch.html#Lazy-Catch

This is why I invented with-throw-handler and the optional
pre-unwind-handler parameter of `catch'.  Perhaps you need to use one
of those instead.

Regards,
     Neil




reply via email to

[Prev in Thread] Current Thread [Next in Thread]