unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* using compensations stacks with Guile
@ 2007-05-02 14:53 Marco Maggi
  2007-05-02 18:07 ` Ludovic Courtès
  0 siblings, 1 reply; 5+ messages in thread
From: Marco Maggi @ 2007-05-02 14:53 UTC (permalink / raw)
  To: guile-user

Ciao,

  I would appreciate if someone can find 5 mins to read:

<http://community.schemewiki.org/?guile-compensation>

and signal to me if there are obvious errors in the
implementation.

TIA.

--
Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: using compensations stacks with Guile
  2007-05-02 14:53 Marco Maggi
@ 2007-05-02 18:07 ` Ludovic Courtès
  0 siblings, 0 replies; 5+ messages in thread
From: Ludovic Courtès @ 2007-05-02 18:07 UTC (permalink / raw)
  To: guile-user

Hi,

"Marco Maggi" <marco.maggi-ipsu@poste.it> writes:

>   I would appreciate if someone can find 5 mins to read:
>
> <http://community.schemewiki.org/?guile-compensation>
>
> and signal to me if there are obvious errors in the
> implementation.

I haven't read the paper you mention there but that looks very similar
to what `dynamic-wind' does.  Given that `with-fluids' is implemented on
top of `dynamic-wind', building a form akin to `dynamic-wind' on top of
`with-fluids' seems a bit counter-productive.  :-)

Or did I miss something?

Thanks,
Ludovic.



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: using compensations stacks with Guile
@ 2007-05-02 19:15 Marco Maggi
  0 siblings, 0 replies; 5+ messages in thread
From: Marco Maggi @ 2007-05-02 19:15 UTC (permalink / raw)
  To: guile-user

"Alan Grover" wrote:
> I noticed "the compensation closures are wrapped in
> false-if-exception: this causes errors to be ignored
> and all the closures to be evaluated." Could you revise
> this to signal the exception? Silently consumption of
> an exception is very frustrating, and surprising.

I have not coded this with the specific purpose of
suppressing an exception: the purpose is to go on
evaluating the other compensation closures even when
one or more of them fail, that way the code tries to
free resources as much as possible.

If you have 5 resources, you free 2 successfully and the
third free function fails: what do you do? If you raise
an exception the last 2 resources will be leaked, unless
you adopt a (IMHO) really complex architecture of context
sharing in your program.

I find this discussion similar to the one related to
exception-raising object destructors in C++: if you throw
an exception, there is no way to go back later and
finish the destruction (a lot of papers/weblogs on the
web about this).

--
Marco Maggi




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: using compensations stacks with Guile
@ 2007-05-02 19:29 Marco Maggi
  0 siblings, 0 replies; 5+ messages in thread
From: Marco Maggi @ 2007-05-02 19:29 UTC (permalink / raw)
  To: guile-user

"Ludovic Courts" wrote:
> I haven't read the paper you mention there but that
> looks very similar to what `dynamic-wind' does.

There are differences between using 'with-compensations'
and using 'dynamic-wind' with alloc forms in the in-guard
and the free forms in the out-guard:

1. 'dynamic-wind' separates the alloc code from the free
   code, while 'compensate' allows them to be one near
   the other;

2. when an error occurs inside the in-guard or inside
   the out-guard the free functions are not invoked;
   with:

   (dynamic-wind
       (lambda ()
         (display 'alloc-a)(newline)
         (display 'alloc-b)(newline)
         (display 'alloc-c)(newline))
       (lambda ()
         (format #t "ciao~%"))
       (lambda ()
         (display 'free-c)(newline)
         (display 'free-b)(newline)
         (display 'free-a)(newline)))

   no error, everything is fine; with:

   (dynamic-wind
    (lambda ()
      (display 'alloc-a)(newline)
      (display 'alloc-b)(newline)
      (display 'alloc-c)(newline))
    (lambda ()
      (format #t "ciao~%")
      (throw 'misc-error))
    (lambda ()
      (display 'free-c)(newline)
      (display 'free-b)(newline)
      (display 'free-a)(newline)))

   'dynamic-wind' does its job, all right; with:

   (dynamic-wind
    (lambda ()
      (display 'alloc-a)(newline)
      (display 'alloc-b)(newline)
      (display 'alloc-c)(newline))
    (lambda ()
      (format #t "ciao~%"))
    (lambda ()
      (display 'free-c)(newline)
      (throw 'misc-error)
      (display 'free-b)(newline)
      (display 'free-a)(newline)))

   'free-b' and 'free-a' are not displayed: a and b are
   leaked; with:

   (dynamic-wind
    (lambda ()
      (display 'alloc-a)(newline)
      (display 'alloc-b)(newline)
      (throw 'misc-error)
      (display 'alloc-c)(newline))
    (lambda ()
      (format #t "ciao~%"))
    (lambda ()
      (display 'free-c)(newline)
      (display 'free-b)(newline)
      (display 'free-a)(newline)))

   'free-a' and 'free-b' are not displayed: a and b are
   leaked; with a compensations stack these cases are
   handled correctly.

--
Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: using compensations stacks with Guile
@ 2007-05-02 20:01 Marco Maggi
  0 siblings, 0 replies; 5+ messages in thread
From: Marco Maggi @ 2007-05-02 20:01 UTC (permalink / raw)
  To: guile-user

"Ludovic Courts" wrote:
> I haven't read the paper you mention there but that
> looks very similar to what `dynamic-wind' does.

[...]

3. 'with-compensations'  does  not  invoke the  compensation
   closures: it can be  used in object constructors, when it
   is required to free only if construction fails.

--
Marco Maggi




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

end of thread, other threads:[~2007-05-02 20:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-02 19:29 using compensations stacks with Guile Marco Maggi
  -- strict thread matches above, loose matches on Subject: below --
2007-05-02 20:01 Marco Maggi
2007-05-02 19:15 Marco Maggi
2007-05-02 14:53 Marco Maggi
2007-05-02 18:07 ` 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).