Subject: Re: Boost::ScopeExit [Re: A "killer" macro]
From: (Rob Warnock)
Date: Thu, 13 Sep 2007 22:33:47 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
D Herring  <> wrote:
| (defun guard-test (person)
|    "Demonstrate the ScopeExit implementation."
|    (let ((commit nil))
|      (with-scope-guard
|        (push person *people*)
|        :scope-guard (unless commit
|                       (pop *people*))
|        ; ... other operations
|        (setf commit t))))
| Which macroexpands to something like
|    (LET ((COMMIT NIL))
|        (PROGN
|          (PUSH PERSON *PEOPLE*)
...        ...[you left out "other operations" here]...
|          (SETF COMMIT T))
|        (PROGN
|          (UNLESS COMMIT
|            (POP *PEOPLE*))))))
| Exactly what we want: no creating lists of variables which need to be 
| preserved, no question of how these variables should be passed, and 
| minimal runtime overhead.  Plus, since Lisp offers unwind-protect, 
| there's no need to manually set the guard variable, commit.
| Is that "killer"?  It took me (a relative Lisp noob) all of 5 minutes 
| to write (less time than this email) -- well less that what has been 
| spent by the collective Boost gurus on their implementation.

While this is true -- and congratulations, by the way, nice job! --
I confess that it *doesn't* really seem to meet the bar for a
"killer macro" to me, given that CL already has UNWIND-PROTECT
in the first place. The raw macroexpanded version is just as easy
to write manually than the WITH-SCOPE-GUARD version. (Sorry!)

Slightly easier, actually, since you really don't need the
second PROGN, given the syntax of UNWIND-PROTECT.


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