summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-01-20 22:59:02 -0800
committerKaz Kylheku <kaz@kylheku.com>2021-01-20 22:59:02 -0800
commit947b0979d05b190fee65698864cd1e14b5797f66 (patch)
tree1e5e93f7e4ba5c69d0bb3815c2eeb30904a74fd7 /txr.1
parentd30af5639c1a3a27452a7cd63c6f91201eac687b (diff)
downloadtxr-947b0979d05b190fee65698864cd1e14b5797f66.tar.gz
txr-947b0979d05b190fee65698864cd1e14b5797f66.tar.bz2
txr-947b0979d05b190fee65698864cd1e14b5797f66.zip
matcher: allow variables to back-reference.
Multiple occurrences of variables unify using equal. * share/txr/stdlib/match.tl (var-list): New struct type. Used for tracking what variables have been defined. (compile-struct-match, compile-vec-match, compile-atom-match, compile-op-match, compile-cons-structure, compile-require-match, compile-let-match, compile-loop-match, compile-parallel-match, compile-not-match): Take var-match argument and pass it down. (compile-parallel-match): Take var-match argument and pass copies of it down to the compile jobs of the branches, since they do not unify. (compile-var-match, comiple-let-match, compile-op-match): Handle variables carefully: check for variable already being defined and generate a backreference instead of a new binding match. (compile-match): Take optional var-list argument, instantiating the object if it is missing, pass down to all recursive compile unctions. * txr.1: Documented.
Diffstat (limited to 'txr.1')
-rw-r--r--txr.123
1 files changed, 23 insertions, 0 deletions
diff --git a/txr.1 b/txr.1
index 860492e2..e4e224b9 100644
--- a/txr.1
+++ b/txr.1
@@ -39646,6 +39646,29 @@ notation. The reason is that a struct literal produces an object
which loses information about how it was specified in the literal syntax,
but those details are critically important in pattern matching.
+A pattern can contain multiple occurrences of the same variable.
+Except in the case when these variables occur in different branches
+of an
+.code @(or)
+or
+.code @(and)
+pattern operator, those repeated variables denote one variable.
+The left-most, or in the case of
+.code @(let)
+nesting, outermost, occurrence of the variable binds to the corresponding
+element of the object. The remaining occurrences of the variable must
+correspond to objects which are
+.code equal
+to that object, or else there is no match.
+For instance, the pattern
+.code "(@a @a)"
+matches a list like
+.code "(1 1)"
+and binds a to the leftmost
+.codn 1 ,
+and fails to match a list like
+.codn "(1 2)" .
+
The pattern-matching notation is documented in the following
sections; sections describing the pattern matching macros follow.