From f3167bfb485df809f2891b0a76404a85883241af Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Tue, 9 Jan 2024 01:18:34 +0100 Subject: [PATCH] add guard macro --- CHANGELOG.md | 2 ++ lib/R7RS.scm | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4969911b..1964755ac 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ ## 1.0.0-beta.18 +### Features +* add R7RS `guard` macro ### Bugfix * remove evaluating of async list data as first argument diff --git a/lib/R7RS.scm b/lib/R7RS.scm index cfac6d9e6..757687063 100755 --- a/lib/R7RS.scm +++ b/lib/R7RS.scm @@ -1184,6 +1184,23 @@ ,@body (--> ,parent (set ',name ,module-var))))) +;; ----------------------------------------------------------------------------- +(define-syntax guard + (syntax-rules (catch) + ((_ (var cond1 cond2 ...) + body ...) + (try + body ... + (catch (var) + (cond cond1 + cond2 ...))))) + "(guard (variable (cond result) + (cond2 result)) + body) + + Macro that executes the body and when there is exception, triggered by + raise it's saved in variable that can be tested by conditions.") + ;; ----------------------------------------------------------------------------- (define-syntax define-library/export (syntax-rules (rename :c)