D Herring <email@example.com> wrote:
| (defun guard-test (person)
| "Demonstrate the ScopeExit implementation."
| (let ((commit nil))
| (push person *people*)
| :scope-guard (unless commit
| (pop *people*))
| ; ... other operations
| (setf commit t))))
| Which macroexpands to something like
| (DEFUN GUARD-TEST (PERSON)
| (LET ((COMMIT NIL))
| (PUSH PERSON *PEOPLE*)
... ...[you left out "other operations" here]...
| (SETF COMMIT T))
| (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 <firstname.lastname@example.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607