License: Public Domain , Load it with Quicklisp: (ql:quickload "enhanced-unwind-protect")
Library type: Wrapper macro , Project complexity: Embarrassingly trivial

enhanced-unwind-protect provides an enhanced unwind-protect that makes it easy
to detect whether the protected form performed a non-local exit or returned normally.

Overview

There is a simple well-known pattern for detecting whether a form performed a non-local exit or returned normally, but calling this macro is more readable, concise, ergonomic and convenient.

Distinguishing non-local exits from normal returns can be useful if you want to detect if some operation has "failed" or "succeeded".
You can't just detect if an error has been signaled, since there might be code upstream that knows how to recover from the error without unwinding the stack enough to trigger the cleanup-forms.

Dictionary

Dictionary » enhanced-unwind-protect

Package enhanced-unwind-protect

Description

Simply (:shadowing-import-from #:enhanced-unwind-protect #:unwind-protect) from your defpackage. Don't (:use)!

Dictionary » unwind-protect

Macro unwind-protect

(&optional abortp) protected-form &body cleanup-forms => results

Arguments and Values

  • abortp -- Not provided, t, nil or a symbol.
  • protected-form -- A form.
  • cleanup-forms -- An implicit progn.
  • results -- The values of the protected-form.

Description

Directly expands to cl:unwind-protect, with trivial variations depending on the abortp argument:

If abortp was not provided, just expand directly to cl:unwind-protect.

If abortp is t, then cleanup-forms will be executed only if protected-form performed a non-local exit.

If abortp is nil, then cleanup-forms will be executed only if protected-form returned normally.

Else, abortp is a variable name, so cleanup-forms will be executed
with abortp bound to t if protected-form performed a non-local exit, or to nil if it returned normally.