diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-02-04 07:09:33 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-02-04 07:09:33 -0800 |
commit | 972e2b968c177e164d3c731718cbfab7b3592e4c (patch) | |
tree | dbafba322ff8988816d1c77d40c783cbe50c4ef0 /share/txr/stdlib/match.tl | |
parent | 726fc85294c3e9954587f7c70e1f8776102d282a (diff) | |
download | txr-972e2b968c177e164d3c731718cbfab7b3592e4c.tar.gz txr-972e2b968c177e164d3c731718cbfab7b3592e4c.tar.bz2 txr-972e2b968c177e164d3c731718cbfab7b3592e4c.zip |
matcher: add :match parameter macro.
With this, we can do matching anywhere we are able to specify
a function parameter list and a body, and we can specify
ordinary arguments, which are inserted to the left of the
implicit match. Plus, it specialy integrates with :key.
* lisplib.c (match_set_entries): Autoload on :match.
* share/txr/stdlib/match.tl (:match): New parameter macro.
* txr.1: Documented.
Diffstat (limited to 'share/txr/stdlib/match.tl')
-rw-r--r-- | share/txr/stdlib/match.tl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/share/txr/stdlib/match.tl b/share/txr/stdlib/match.tl index e2a55256..8932cc71 100644 --- a/share/txr/stdlib/match.tl +++ b/share/txr/stdlib/match.tl @@ -678,6 +678,19 @@ (tree-bind (lambda args . body) (expand-lambda-match clauses) ^(defun ,name ,args . ,body))) +(define-param-expander :match (params clauses menv form) + (unless (proper-list-p params) + (compile-error form "~s is incompatible with dotted parameter lists" :match)) + (when (find : params) + (compile-error form "~s is incompatible with optional parameters" :match)) + (tree-bind (lambda lparams . body) (expand-lambda-match clauses) + (let ((dashdash (member '-- params))) + (cons (append (ldiff params dashdash) + (butlastn 0 lparams) + dashdash + (nthlast 0 lparams)) + body)))) + (defun non-triv-pat-p (syntax) t) (defun non-triv-pat-p (syntax) |