summaryrefslogtreecommitdiffstats
path: root/share/txr/stdlib/match.tl
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 /share/txr/stdlib/match.tl
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 'share/txr/stdlib/match.tl')
-rw-r--r--share/txr/stdlib/match.tl25
1 files changed, 25 insertions, 0 deletions
diff --git a/share/txr/stdlib/match.tl b/share/txr/stdlib/match.tl
index baa65f0d..3502688b 100644
--- a/share/txr/stdlib/match.tl
+++ b/share/txr/stdlib/match.tl
@@ -643,6 +643,14 @@
,result
,else)))))
+(defmacro while-match (:form *match-form* :env e pat obj . body)
+ (let ((cm (compile-match pat : (get-var-list e))))
+ ^(for ()
+ ((alet ((,cm.obj-var ,obj))
+ (let ,cm.(get-vars)
+ ,cm.(wrap-guards ^(progn ,*body t)))))
+ ())))
+
(defmacro match-case (:form *match-form* :env e obj . clauses)
(unless [all clauses [andf proper-listp [chain len plusp]]]
(compile-error *match-form* "bad clause syntax"))
@@ -666,6 +674,23 @@
(or ,*clause-code)
,result-temp))))
+(defmacro while-match-case (:form *match-form* :env e obj . clauses)
+ (unless [all clauses [andf proper-listp [chain len plusp]]]
+ (compile-error *match-form* "bad clause syntax"))
+ ^(for ()
+ ((match-case ,obj
+ ,*(mapcar (ret ^(,(car @1) ,*(cdr @1) t)) clauses)))
+ ()))
+
+(defmacro while-true-match-case (:form *match-form* :env e obj . clauses)
+ (unless [all clauses [andf proper-listp [chain len plusp]]]
+ (compile-error *match-form* "bad clause syntax"))
+ ^(for ()
+ ((match-case ,obj
+ (nil)
+ ,*(mapcar (ret ^(,(car @1) ,*(cdr @1) t)) clauses)))
+ ()))
+
(defmacro when-exprs-match (:form *match-form* :env e pats exprs . forms)
(let ((em (compile-match ^@(exprs ,*pats) exprs (get-var-list e))))
^(let* (,*em.(get-vars))