From 3fb32c9a73d407844fb9f7c843f70f85bee5b60e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 22 Jan 2021 07:22:55 -0800 Subject: matcher: add optimized special case to hash pattern. This change causes a key-value pattern like (@a @b) to be treated specially when @a already has a binding from a previous pattern. In this case, it behaves like the trivial key case: the value of @a is looked up to try to find a single value. If @a is not bound, then the exhaustive search takes place, using equal equality. * share/txr/stdlib/match.tl (compile-hash-match): Implement special case. (var-pat-p): New function. * tests/011/patmatch.tl: Existing test case now changes value. New test case added. * txr.1: Documented. --- tests/011/patmatch.tl | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/011') diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl index a9bd57fa..d045c45b 100644 --- a/tests/011/patmatch.tl +++ b/tests/011/patmatch.tl @@ -131,4 +131,7 @@ (3 5 3 6 (11 12) (2 time) (2020 1) (vec tor))) (test (when-match @(hash (x @y) (@y @datum)) #H(() (x k) (k 42)) datum) + 42) + +(test (when-match @(hash (x @y) (@(symbolp y) @datum)) #H(() (x k) (k 42)) datum) (42)) -- cgit v1.2.3