aboutsummaryrefslogtreecommitdiffstats
path: root/match.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-01-11 21:52:57 -0800
committerRose Hogenson <rhogenson@posteo.net>2022-01-11 21:52:57 -0800
commitc5fc92c75205051ce01bba1781cd1c4ba0907765 (patch)
tree2ebd286d8393144dfb600687d9c8f958f5edcbcb /match.csc
parentAdd guards to the match syntax. (diff)
downloadchromatopelma-c5fc92c75205051ce01bba1781cd1c4ba0907765.tar.zst
Make bindings visible while a guard is evaluated.
The current implementation repeats the bindings twice, but I guess it's fine. It seems to work.
Diffstat (limited to 'match.csc')
-rw-r--r--match.csc9
1 files changed, 5 insertions, 4 deletions
diff --git a/match.csc b/match.csc
index d188349..3e02937 100644
--- a/match.csc
+++ b/match.csc
@@ -42,15 +42,16 @@
(define-syntax match
(syntax-rules (when)
((match x (pattern (when condition) result result* ...))
- (if (and (matches? x pattern)
- condition)
- (bind-pattern x pattern result result* ...)))
+ (if (matches? x pattern)
+ (bind-pattern x pattern
+ (if condition
+ (begin result result* ...)))))
((match x (pattern result1 result2 ...))
(if (matches? x pattern)
(bind-pattern x pattern result1 result2 ...)))
((match x (pattern (when condition) result result* ...) clause clause* ...)
(if (and (matches? x pattern)
- condition)
+ (bind-pattern x pattern condition))
(bind-pattern x pattern result result* ...)
(match x clause clause* ...)))
((match x (pattern result1 result2 ...) clause1 clause2 ...)