summaryrefslogtreecommitdiffstats
path: root/tests/011
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-24 08:41:58 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-24 08:41:58 -0700
commitf2f951350516e4b959ef28f220e31b91b466fa16 (patch)
treeee4958ffcac59dcfb909ca5e217d5a74a42b1569 /tests/011
parent7b587fe3450c949f454778bfaf71870a5a872f6b (diff)
downloadtxr-f2f951350516e4b959ef28f220e31b91b466fa16.tar.gz
txr-f2f951350516e4b959ef28f220e31b91b466fa16.tar.bz2
txr-f2f951350516e4b959ef28f220e31b91b466fa16.zip
matcher: allow hash pattern to omit values.
The @(hash ...) operator now allows key-only patterns like (42) or (@x), where x could be bound or unbound. This has separate semantics from when a value is present. * share/txr/stdlib/match.tl (compile-hash-match): Implement. * tests/011/patmatch.tl: Test. * txr.1: Document.
Diffstat (limited to 'tests/011')
-rw-r--r--tests/011/patmatch.tl7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl
index 85adb352..071243fb 100644
--- a/tests/011/patmatch.tl
+++ b/tests/011/patmatch.tl
@@ -187,6 +187,13 @@
(42))
(mtest
+ (when-match @(hash (a)) #H(() (a b)) t) t
+ (when-match @(hash (c)) #H(() (a b)) t) nil
+ (let ((x 'a)) (when-match @(hash (@x)) #H(() (a b)) t)) t
+ (let ((x 'd)) (when-match @(hash (@x)) #H(() (a b)) t)) nil
+ (when-match @(hash (@x)) #H(() (a b)) x) (a))
+
+(mtest
(if-match #R(10 20) 10..20 :yes :no) :yes
(if-match #R(10 20) #R(10 20) :yes :no) :yes
(if-match #R(10 20) #R(1 2) :yes :no) :no