summaryrefslogtreecommitdiffstats
path: root/tests/011/patmatch.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-03-23 07:37:57 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-03-23 07:37:57 -0700
commitbf82e9cfa8fc2b627af6e2fcfcbc1bbfc61e63d9 (patch)
tree1fb96bf438be30420dcc50f376b9e5d4996a8aae /tests/011/patmatch.tl
parent5861192436b31f7377bd82cacb7acc8cc8baf4f9 (diff)
downloadtxr-bf82e9cfa8fc2b627af6e2fcfcbc1bbfc61e63d9.tar.gz
txr-bf82e9cfa8fc2b627af6e2fcfcbc1bbfc61e63d9.tar.bz2
txr-bf82e9cfa8fc2b627af6e2fcfcbc1bbfc61e63d9.zip
match: support @nil in predicates.
For instance @(<= 10 @nil 20) is a pattern which matches a number between 10 and 20, without binding a variable. * stdlib/match.tl (compile-predicate-match): Looks like this code was already halfway expressing the intent that the avar could be nil, because arg-var takes the value of avar if that is non-nil, otherwise a gensym is substituted. What was missing was that the gensym that replaces nil must also be substituted into the predicate. * tests/011/patmatch.tl: New tests. * txr.1: Document that the variable embedded in a predicate may be null.
Diffstat (limited to 'tests/011/patmatch.tl')
-rw-r--r--tests/011/patmatch.tl8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl
index 5e8d3f7f..bace28ce 100644
--- a/tests/011/patmatch.tl
+++ b/tests/011/patmatch.tl
@@ -560,3 +560,11 @@
(match @`foo-@a` "foo-abc" a) "abc"
(match ^(,`foo-@a`) '("foo-abc") a) "abc"
(match ^#J[~`foo-@a`] #("foo-abc") a) "abc")
+
+(mtest
+ (match @(< @nil 0) -1 42) 42
+ (match @(> 0 @nil) -1 42) 42
+ (if-match @(< @nil 0) 1 :y :n) :n
+ (if-match @(< @nil 2) 1 :y :n) :y
+ (match @(@nil (< @x 0)) -1 x) -1
+ (match @(@nil (< @nil 0)) -1 t) t)