Immediately after switching the page, it will work with CSR.
Please reload your browser to see how it works.
TXR Lisp:
1> (match (@a @(= (+ a 1))) '(1 3) a)
** match: (@a @(= (+ a 1))) failed to match object (1 3)
1> (match (@a @(= (+ a 1))) '(1 2) a)
1
An expression is treated as a predicate. The object being matched, like 2, is inserted as a right argument into it: (= (+ a 1) <obj>).If you try the following, you get a surprising result:
2> (match (@a @(+ a 1)) '(1 3) a)
1
It is more verbose, but we can do more. We don't have to test for exact equality; e.g. @(< a) will match something that is greater than the previously matched a.Capture a b that is greater than previously captured a:
3> (match (@a @(< a @b)) '(1 3) (list a b))
(1 3)
Or fail trying: 4> (match (@a @(< a @b)) '(1 0) (list a b))
** match: (@a @(< a @b)) failed to match object (1 0)
We could treat certain functions differently; since + isn't a relational function producing a Boolean result, equality could be inserted implicitly to generate a predicate.But, rather than that hack, there is a different one: user-defined patterns. We can have @(+ a 1) as a pattern by defining + as a pattern operator:
1> (defmatch + (. args) ^@(= (+ ,*args)))
+
Then: 2> (match (@a @(+ a 1)) '(1 2) a)
1
3> (match (@a @(+ a 1)) '(1 3) a)
** match: (@a @(+ a 1)) failed to match object (1 3)
https://en.wikipedia.org/wiki/Unification_(computer_science)...
> Not a single "match" statement.
This post could increase its reach by explaining why a let statement is pattern matching, or at least point to a reference.
Although I understand people who don't know this already are not the target audience.
Here's the reference for those who need it: https://doc.rust-lang.org/book/ch18-01-all-the-places-for-pa...