diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-04-19 07:56:35 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-04-19 07:56:35 -0700 |
commit | 570de4a6b80e5029f3df3b8a2e022e5ec9087b37 (patch) | |
tree | dca4d10a9265518fa4ab8e6546b3df5b648cb839 | |
parent | f19514a211ad89f32876f6090dcc2212126b913c (diff) | |
download | txr-570de4a6b80e5029f3df3b8a2e022e5ec9087b37.tar.gz txr-570de4a6b80e5029f3df3b8a2e022e5ec9087b37.tar.bz2 txr-570de4a6b80e5029f3df3b8a2e022e5ec9087b37.zip |
defmatch: pass form to mac-param-bind.
* share/txr/stdlib/match.tl (defmatch): Pass *match-form* to
mac-param-bind so that the context is available to defmatch
macros via the :form parameter.
* txr.1: Documented use of :form in defmatch.
-rw-r--r-- | share/txr/stdlib/match.tl | 2 | ||||
-rw-r--r-- | txr.1 | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/share/txr/stdlib/match.tl b/share/txr/stdlib/match.tl index d8af1baf..91885472 100644 --- a/share/txr/stdlib/match.tl +++ b/share/txr/stdlib/match.tl @@ -751,7 +751,7 @@ ^(progn (sethash *match-macro* ',name (lambda (,args) - (mac-param-bind ,args + (mac-param-bind *match-form* (,name-dummy ,*destructuring-args) ,args ,*body))) ',name))) @@ -41934,6 +41934,19 @@ The pattern macro bindings are stored in a hash table held by the variable whose keys are symbols, and whose values are expander functions. There are no lexically scoped pattern macros. +If a +.code defmatch +macro uses the +.code :form +parameter to gain access to the form, what the parameter retrieves +is the pattern matching form, or a constituent thereof, in which the +the macro is being invoked. For instance, if the operator is being used +inside a pattern given to a +.code when-match +macro invocation, then the form will be that entire +.code when-match +form. + .TP* Example: .verb @@ -41945,6 +41958,15 @@ There are no lexically scoped pattern macros. ;; use the macro in matching: (when-match @(let x @(or foo bar)) 'foo x) + + ;; Error reporting example using :form + + (defmatch foo (sym) + (unless (bindable sym) + (compile-error *match-form* + "~s: bindable symbol expected, not ~s" + 'foo sym)) + ...) .brev .coNP Special variable @ *match-macro* |