diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-01-22 07:22:55 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-01-22 07:22:55 -0800 |
commit | 3fb32c9a73d407844fb9f7c843f70f85bee5b60e (patch) | |
tree | 211129e7609cf1c3140d915c16c2311529ddb1ce /tests/011 | |
parent | 1e8dc4f05dc5149f682ac16f3d368ec0fc82cf58 (diff) | |
download | txr-3fb32c9a73d407844fb9f7c843f70f85bee5b60e.tar.gz txr-3fb32c9a73d407844fb9f7c843f70f85bee5b60e.tar.bz2 txr-3fb32c9a73d407844fb9f7c843f70f85bee5b60e.zip |
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.
Diffstat (limited to 'tests/011')
-rw-r--r-- | tests/011/patmatch.tl | 3 |
1 files changed, 3 insertions, 0 deletions
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)) |