From a5f90cf8a467ac8817ab3db5c9f8190b7a547d67 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 22 Jan 2021 00:17:46 -0800 Subject: matcher: existing variables in @(all) now backref. This commit fixes the inadequacy that all variables occurring in a pattern under @(all ...) or @(coll ...) are blindly collated into lists, ignoring the fact that they may be previously bound variables that must back-reference and not be colleced into lists (just like in the TXR Pattern language!) * share/txr/stdlib/match.tl (compile-loop-match): Calculate the subset of variables in the pattern that have been freshly bound. Only generate the collection gensyms for those variables and only collect and nreverse those variables. * tests/011/patmatch.tl: Some test cases that backreference into an @(all). * txr.1: Documented. --- tests/011/patmatch.tl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/011') diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl index 11a6a933..2b1e26c8 100644 --- a/tests/011/patmatch.tl +++ b/tests/011/patmatch.tl @@ -54,6 +54,10 @@ (list a b)) ((1 2 3) (a b c))) +(test (when-match (@x @(all @x)) '(1 (1 1 1 1)) x) 1) + +(test (when-match (@x @(all @x)) '(1 (1 1 1 2)) x) nil) + (test (when-match @(some (x @a @b)) '((y 1 a) (x 2 b) (z 3 c)) (list a b)) (2 b)) -- cgit v1.2.3