From eaece56148ae3560c4c249dd0fc9b63dd65d4fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 17 Mar 2022 22:23:01 +0100 Subject: Add catch* --- doc/ref/guile/util.texi | 6 ++++++ module/hnh/util.scm | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/doc/ref/guile/util.texi b/doc/ref/guile/util.texi index 2cf1070b..3f37491d 100644 --- a/doc/ref/guile/util.texi +++ b/doc/ref/guile/util.texi @@ -338,6 +338,12 @@ Similar to @var{let}, but sets environment variables for the code in body. Restores the old values once we leave. @end defmac +@defmac catch* thunk (symbol proc) ... +Macro allowing multiple exception types to be caught. Each (symbol +proc) pair expands to a regular @code{catch}, with the leftmost being +innermost. +@end defmac + @subsection UUID generation Provided by module @code{(hnh util uuid)}. diff --git a/module/hnh/util.scm b/module/hnh/util.scm index e766cd0a..3019b35b 100644 --- a/module/hnh/util.scm +++ b/module/hnh/util.scm @@ -13,6 +13,7 @@ and=>> label print-and-return begin1 + catch* ) #:replace (let* set! define-syntax when unless)) @@ -577,3 +578,11 @@ (lambda () (for-each (lambda (pair) (setenv (car pair) (caddr pair))) env-pairs))))])) + +(define-syntax catch* + (syntax-rules () + ((_ thunk (key handler)) + (catch (quote key) thunk handler)) + ((_ thunk (key handler) rest ...) + (catch* (lambda () (catch (quote key) thunk handler)) + rest ...)))) -- cgit v1.2.3