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. --- txr.1 | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index ce6f045f..5fbf346f 100644 --- a/txr.1 +++ b/txr.1 @@ -40109,7 +40109,7 @@ The specified .meta pattern is applied against every element of the sequence. The match is successful if .meta pattern -finds a matching element. +matches at least one element. Variables are extracted from the first matching which is found. @@ -40125,6 +40125,34 @@ Variables are extracted from the first matching which is found. -> (2 b) .brev +.coNP Pattern operator @ coll +.synb +.mets @(coll << pattern ) +.syne +.desc +The +.code coll +pattern operator requires the corresponding object to be a sequence. +The specified +.meta pattern +is applied against every element of the sequence. The match is successful if +.meta pattern +matches at least one element. + +Variables are extracted from all matching elements, and collected into +parallel lists, just like with the +.code @(all) +operator. + +.TP* Example: + +.verb + (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)) +.brev + .coNP Pattern operators @ and and @ or .synb .mets @(and << pattern *) -- cgit v1.2.3