try-catch() try-catch-finally() errors()

master
Avril 5 years ago
parent 93bedbc880
commit b95295edef
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -39,6 +39,26 @@
;;; --- actual (exported) code goes here --
(defmacro errors (stmt)
`(let ((ret (handler-case (cons ,stmt nil)
(t (c) (cons nil c)))))
(values (car ret) (cdr ret))))
(defmacro try-catch (try &body catch)
(let ((errnm (gensym)))
`(let ((,errnm (handler-case (cons ,try nil)
(t (e)
(cons (progn ,@catch) e)))))
(if (cdr ,errnm)
(values (car ,errnm) (cdr ,errnm))
(values (car ,errnm) nil)))))
(defmacro try-catch-finally (try catch &body finally)
(let ((ret (gensym))
(err (gensym)))
`(multiple-value-bind (,ret ,err) (try-catch ,try ,catch)
(values (progn ,@finally) ,ret ,err))))
(defmacro val-if-or (val test or)
"(if (test val) val or)"
`(let ((vv ,val))

Loading…
Cancel
Save