From d02854155e915e28740605a7302faaaff1128622 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 5 Feb 2021 19:30:28 -0800 Subject: matcher: rearrange match order of @(with). The @(with side-pat expr main-pat) syntax becomes @(with main-pat side-pat expr), which is more useful. Also, the main-pat can be omitted. * share/txr/stdlib/match.tl (compile-with-match): Recognize two forms of the syntax: two argument form with main-pat omitted and the full form. In the full form, main-pat is on the left now and processed first, so we have to rearrange the compilation and integration order. * tests/011/patmatch.tl: Existing tests updated. Two-argument test added. * txr.1: Updated. --- tests/011/patmatch.tl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl index 5dd735b9..fe82d28c 100644 --- a/tests/011/patmatch.tl +++ b/tests/011/patmatch.tl @@ -120,14 +120,19 @@ (test (when-match (@a @(as a @(or x @a))) '(#1=(1 2 #1# 3) #1#) :yes) :yes) -(test (when-match (@(with x 42 @a) @b @c) '(1 2 3) (list a b c x)) +(test (when-match (@(with @a x 42) @b @c) '(1 2 3) (list a b c x)) (1 2 3 42)) (test (let ((o 3)) - (when-match (@(evenp x) @(with @(oddp y) o @z)) '(4 6) + (when-match (@(evenp x) @(with @z @(oddp y) o)) '(4 6) (list x y z))) (4 3 6)) +(test (let ((o 3)) + (when-match (@(evenp x) @(with @(oddp y) o)) '(4 6) + (list x y))) + (4 3)) + (defstruct node () left right) -- cgit v1.2.3