diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-02-05 21:51:04 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-02-05 21:51:04 -0800 |
commit | a9870a810fda3bd415f4250188f0af17e53fe759 (patch) | |
tree | 9e56bd688f2f77c6e7f758a97f891ec47dd69d3a /tests | |
parent | 05f4a2d0d33c5e2cdc0569775cf8218824c7078e (diff) | |
download | txr-a9870a810fda3bd415f4250188f0af17e53fe759.tar.gz txr-a9870a810fda3bd415f4250188f0af17e53fe759.tar.bz2 txr-a9870a810fda3bd415f4250188f0af17e53fe759.zip |
matcher: back-reference Lisp variables.
* share/txr/stdlib/match.tl (struct var-list): New slot, menv.
(var-list exists): Method now falls back on lexical scope and
dynamic variables.
(get-var-list): New function.
(when-match, if-match, match-case, when-exprs-match): Capture
macro environment and use get-vars-list to convert to a vars
object which carries it as the menv slot. With this, the
compiler framework has access to the lexical environment.
* tests/011/patmatch.tl: Test cases of back-referencing with
Lisp lexicals.
* txr.1: Documented.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/011/patmatch.tl | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl index fe82d28c..870a3a0b 100644 --- a/tests/011/patmatch.tl +++ b/tests/011/patmatch.tl @@ -241,3 +241,24 @@ (test (ack 1 1) 3) (test (ack 2 2) 7) + +(defun x-x-y (list x) + (when-match (@x @x @y) list y)) + +(test (x-x-y '(1 1 2) 1) 2) +(test (x-x-y '(1 2 3) 1) nil) +(test (x-x-y '(1 1 2 r2) 1) nil) + +(test (let ((a 3) (x 0)) + (match-case '(3 2 1) + ((@x 2 @b) ^(1 ,b)) + ((@a 2 @b) ^(2 ,a)))) + (2 3)) + +(test + (let ((a 3) (x 0)) + (labels ((local (:match) + ((@x 2 @b) ^(1 ,b)) + ((@a 2 @b) ^(2 ,a)))) + (local 3 2 1))) + (2 3)) |