diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-01-25 23:30:59 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-01-25 23:30:59 -0800 |
commit | 030f25146ff5d2f6671ef1b615fc4217004632e5 (patch) | |
tree | 22e2cfd627d4120c933d58ce22b2091fb66e2abd /share | |
parent | 433208fa8537821178a08ee04af9575344aa4b28 (diff) | |
download | txr-030f25146ff5d2f6671ef1b615fc4217004632e5.tar.gz txr-030f25146ff5d2f6671ef1b615fc4217004632e5.tar.bz2 txr-030f25146ff5d2f6671ef1b615fc4217004632e5.zip |
matcher: allow @[...] predicate notation.
* share/txr/stdlib/match.tl (compile-dwim-predicate-match):
New function.
(compile-match): Route dwim symbol to
compile-dwim-predicate-match.
* txr.1: Documented.
Diffstat (limited to 'share')
-rw-r--r-- | share/txr/stdlib/match.tl | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/share/txr/stdlib/match.tl b/share/txr/stdlib/match.tl index d1c45559..00918f37 100644 --- a/share/txr/stdlib/match.tl +++ b/share/txr/stdlib/match.tl @@ -194,6 +194,14 @@ (set var-match.test-expr ^(and ,var-match.test-expr [,op-expr ,obj-var])) var-match)) +(defun compile-dwim-predicate-match (pred-expr obj-var var-list) + (mac-param-bind *match-form* (dwim fun : sym) pred-expr + (or (null sym) (bindable sym) + (compile-error *match-form* "~s is not a symbol" sym)) + (let ((var-match (compile-var-match sym obj-var var-list))) + (set var-match.test-expr ^(and ,var-match.test-expr [,fun ,obj-var])) + var-match))) + (defun compile-predicate-match (pred-expr obj-var var-list) (mac-param-bind *match-form* (fun : sym) pred-expr (or (null sym) (bindable sym) @@ -426,6 +434,7 @@ (op (compile-op-match exp obj-var var-list)) (hash (compile-hash-match exp obj-var var-list)) (rcons (compile-range-match exp obj-var var-list)) + (dwim (compile-dwim-predicate-match exp obj-var var-list)) (t (compile-predicate-match exp obj-var var-list))) (compile-error *match-form* "unrecognized pattern syntax ~s" pat)))) |