summaryrefslogtreecommitdiffstats
path: root/tests/011
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-24 07:00:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-24 08:27:31 -0700
commit65f1445db0d677189ab01635906869bfda56d3d9 (patch)
tree211eb1dc4a327386d49c169b5941b205d6051969 /tests/011
parente4616095db06980eb3f9e80f6e9df60dfc46dfa9 (diff)
downloadtxr-65f1445db0d677189ab01635906869bfda56d3d9.tar.gz
txr-65f1445db0d677189ab01635906869bfda56d3d9.tar.bz2
txr-65f1445db0d677189ab01635906869bfda56d3d9.zip
matcher: new looping macros.
* lisplib.c (match_set_entries): Autoload on new while-match, while-match-case and while-true-match-case symbols. * share/txr/stdlib/match.tl (while-match, while-match-case, while-true-match-case): New macros. * tests/011/patmatch.tl: Tests. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'tests/011')
-rw-r--r--tests/011/patmatch.tl25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl
index aea891c3..9647c52b 100644
--- a/tests/011/patmatch.tl
+++ b/tests/011/patmatch.tl
@@ -488,6 +488,31 @@
datum) (42.0)
(when-match ^#J{"foo" : {"x" : ~val}} #J{"foo" : {"x" : "y"}} val) "y")
+(test
+ (let ((a '(1 2 3 4)))
+ (build
+ (while-match @(true @x) (pop a)
+ (add (* 10 x)))))
+ (10 20 30 40))
+
+(test
+ (let ((a '(1 (2 3) 4 (5 6))))
+ (build
+ (while-match-case (pop a)
+ ((@x @y) (add :pair x y))
+ (@(numberp @x) (add :num x)))))
+ (:num 1 :pair 2 3 :num 4 :pair 5 6))
+
+(test
+ (let ((a '(1 (2 3) 4 (5 6))))
+ (build
+ (while-true-match-case (pop a)
+ ((@x @y) (add :pair x y))
+ (@(evenp @x) (add :even x))
+ (@(oddp @x) (add :odd x))
+ (@else (error "unhandled case")))))
+ (:odd 1 :pair 2 3 :even 4 :pair 5 6))
+
(compile-only
(eval-only
(compile-file (base-name *load-path*) "temp.tlo")