Subject: Re: Boost::ScopeExit [Re: A "killer" macro]
From: (Rob Warnock)
Date: Fri, 14 Sep 2007 00:01:03 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
D Herring  <> wrote:
| Rob Warnock wrote:
| > ...[elided]...
| The point of ScopeExit is to localize the cleanup code with what's 
| being cleaned up, and delay evaluation until exit from the entire 
| function.  This trivial example doesn't show any benefit -- a 100-line 
| function body containing several ScopeExits might be another story. 
| In that case, a raw unwind-protect might put 50 lines between the 
| action and its conditional cleanup.

Aha! yes, I'd overlooked that part of it. You're correct.

| > Slightly easier, actually, since you really don't need the
| > second PROGN, given the syntax of UNWIND-PROTECT.
| The second progn is there to handle multiple :scope-guard clauses. 

My point was just that UNWIND-PROTECT already accepts multiple
forms in the cleanup section, so the second PROGN is redundant.
You can just ",@" the list of cleanup forms directly into the
UNWIND-PROTECT being generated.

| What's missing is a gensym to auto-generate the "complete" flag
| that conditions the execution of :scope-cleanup clauses.

What would be useful is to be able to name each of the ScopeExits,
and then MACROLET a COMMIT macro that takes a name that maps to
the correct LET-bound GENSYM'd boolean. That is, something like:

       (scope-exit (foo)
       (commit foo)

So at the beginning WITH-SCOPE-EXITS would "(LET ((#:G123 nil) ...) ..."
[where #:G123 is the GENSYM the macro assigned to FOO], and then
the (COMMIT FOO) would expand to (SETF #:G123 T), and then one
of the cleanup forms for the UNWIND-PROTECT would be:

        (unless #:G123

Is that what you're talking about?


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607