From 88b3ac140300a6014e271ff02e0e6901d35f18d1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 22 Jan 2021 06:27:40 -0800 Subject: 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. --- share/txr/stdlib/match.tl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'share') 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))) -- cgit v1.2.3