aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--match-test.csc11
-rw-r--r--match.csc9
2 files changed, 15 insertions, 5 deletions
diff --git a/match-test.csc b/match-test.csc
index bbecce4..31e7afa 100644
--- a/match-test.csc
+++ b/match-test.csc
@@ -74,5 +74,14 @@
(match 'b
((! 'a) 1)
((! 'b) (when #f) 2)
- ((! 'b) 3)
+ ((! 'b) (when #t) 3)
(_ 4))))
+
+
+(test match-when-depending-on-pattern-variable
+ (assert-equal
+ 2
+ (match 10
+ (n (when (= 1 n)) 1)
+ (n (when (= 10 n)) 2)
+ (_ 3))))
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 ...)