5 ;; Here is the desired behavior of errset:
7 ;; (let ((errset t)) (errset (+ 2 'a))) ;==> signals error
8 ;; (let ((errset nil)) (errset (+ 2 'a))) ;==> nil
9 ;; (let ((errset nil)) (errset (values))) ;==> (nil)
10 ;; (let ((errset nil)) (errset (+ 2 3))) ;==> (5)
11 ;; (let ((errset nil)) (errset (floor 4/3))) ;==> (1 1/3)
13 ;; Notice that there is one ambiguous case: a singleton list
14 ;; containing only nil could mean either the form really did
15 ;; return nil, or that the form returned no values at all.
16 ;; The original "single value" errset had this ambiguous case,
17 ;; and it was preserved explicitly in this "multiple value"
18 ;; errset for backward-compatibility and to avoid the ambiguous
19 ;; case where nil could be returned if an error occurred or if
20 ;; the form returned no values.
22 (defmacro errset
(&rest l
)
23 `(handler-case (or (multiple-value-list ,(car l
)) (list nil
))
24 (error (e) (when errset
(error e
)))))