[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using compensations stacks with Guile
From: |
Marco Maggi |
Subject: |
Re: using compensations stacks with Guile |
Date: |
Wed, 2 May 2007 21:29:15 +0200 |
"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"