diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-01-22 06:27:40 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-01-22 06:27:40 -0800 |
commit | 88b3ac140300a6014e271ff02e0e6901d35f18d1 (patch) | |
tree | 9ce88c5f5b1a329cb9bbdb66efb35293b7dde871 /share | |
parent | 79e8b2534690bf7c427c28de7738705d5a372502 (diff) | |
download | txr-88b3ac140300a6014e271ff02e0e6901d35f18d1.tar.gz txr-88b3ac140300a6014e271ff02e0e6901d35f18d1.tar.bz2 txr-88b3ac140300a6014e271ff02e0e6901d35f18d1.zip |
matcher: document hash and some fixes.
* share/txr/stdlib/match.tl (compile-hash-match): Follow
rename of is-pattern function to non-triv-pat-p.
(is-pattern): Renamed to non-triv-pat-p, to follow terminology
in the reference manual. A bug is fixed here: we must
recognize cons patterns with operators and variables in the
dotted position as non-trivial.
* tests/011/patmatch.tl: New hash test case, from doc.
* txr.1: Documented hash pattern operator.
Diffstat (limited to 'share')
-rw-r--r-- | share/txr/stdlib/match.tl | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/share/txr/stdlib/match.tl b/share/txr/stdlib/match.tl index 8cb29622..b6dcd442 100644 --- a/share/txr/stdlib/match.tl +++ b/share/txr/stdlib/match.tl @@ -318,8 +318,8 @@ (hash-matches (collect-each ((pair pairs)) (mac-param-bind *match-form* (key val) pair - (let ((key-pat-p (is-pattern key)) - (val-pat-p (is-pattern val))) + (let ((key-pat-p (non-triv-pat-p key)) + (val-pat-p (non-triv-pat-p val))) (cond ((and key-pat-p val-pat-p) (set need-alist-p t) @@ -436,8 +436,10 @@ ^(defun ,name (. ,args) (match-case ,args ,*clauses)))) -(defun is-pattern (syntax) +(defun non-triv-pat-p (syntax) (match-case syntax ((@(op eq 'sys:expr) (@(bindable) . @nil)) t) ((@(op eq 'sys:var) @(bindable) . @nil) t) - (@(some @(is-pattern)) t))) + ((@pat . @rest) (or (non-triv-pat-p pat) + (non-triv-pat-p rest))) + (@(some @(non-triv-pat-p)) t))) |