From 49e6d4d9651f706c517c65e14b00b8a233c59aa1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 21 Jan 2021 21:00:12 -0800 Subject: matcher: new @(coll) operator. * share/txr/stdlib/match.tl (compile-loop-match): Implement coll semantics. coll fails if it collects nothing, which uses common logic with all*. We just have to move the flipping of the loop-iterated-var into the match, and not do it unconditionally for every iteration. (compile-match): Hook in the coll operator. * tests/011/patmatch.tl: Test case copied from doc example. * 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 493f4b2d..11a6a933 100644 --- a/tests/011/patmatch.tl +++ b/tests/011/patmatch.tl @@ -58,6 +58,10 @@ (list a b)) (2 b)) +(test (when-match @(coll (x @a @b)) '((y 1 a) (x 2 b) (z 3 c) (x 4 d)) + (list a b)) + ((2 4) (b d))) + (test (if-match @(and (@x 2 3) (1 @y 3) (1 2 @z)) '(1 2 3) (list x y z)) (1 2 3)) -- cgit v1.2.3