Package: alexandria

Macro unwind-protect-case

Lambda List

unwind-protect-case ((&optional abort-flag) protected-form &body clauses)

Syntax

clauses ::= (:NORMAL form*)* | (:ABORT form*)* | (:ALWAYS form*)*

Arguments

abort-flag -- one of the symbols :normal, :abort, or always
proteced-form -- a form

Return Value

the values of the protected-form

Details

Like unwind-protect, but you can specify the circumstances that the cleanup clauses are run.

Clauses can be given in any order, and more than one clause can be given for each circumstance. The clauses whose denoted circumstance occured, are executed in the order the clauses appear.

abort-flag is the name of a variable that will be bound to t in clauses if the protected-form aborted preemptively, and to nil otherwise.

Examples

 (unwind-protect-case ()
     (protected-form)
    (:normal (format t "Evaluated if PROTECTED-FORM executed normally.~%"))
    (:abort  (format t "Evaluated if PROTECTED-FORM aborted preemptively.~%"))
    (:always (format t "Evaluated in either case.~%")))

(unwind-protect-case (aborted-p) (protected-form) (:always (perform-cleanup-if aborted-p)))