summaryrefslogtreecommitdiffstats
path: root/tests/011
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-05-27 19:44:47 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-05-27 19:44:47 -0700
commit0d9055c632941d3db815474d65fcaa17d9ac4988 (patch)
tree34d0d4a1d946b8f73dccf326cdf49c22ad4e06b2 /tests/011
parenta47eeaf8df2585299844942cbe98b43af4ccc55d (diff)
downloadtxr-0d9055c632941d3db815474d65fcaa17d9ac4988.tar.gz
txr-0d9055c632941d3db815474d65fcaa17d9ac4988.tar.bz2
txr-0d9055c632941d3db815474d65fcaa17d9ac4988.zip
expander: support param macros in nested macro param lists.
Parameter list macros work in inside macro parameter lists, like they do in function parameter lists. However, they ony work at the top level. Macro parameter lists are nested; they may contain nested parameter lists that match corresponding shapes in the argument list. This patch extends parameter list macros to work in nested macro parameter lists. * eval.c (expand_opt_params_rec, expand_params_rec): These two functions must be extended to take a body argument, and to return not just an expanded parameter list but a parameter list accompanied by a body. We do that by making them return a cons cell, whose car is the expanded parameter list and the cdr is the possibly transformed body. Additionally, these functions now call expand_param_macro on nested macro parameter lists. (expand_params): This function becomes slightly simpler as a result of the above changes. Because expand_params_rec already returns a cons cell holding a parameter list and body, we just return that as-is. * tests/011/keyparams.tl: Added some tests of this, vie the standard :key parameter list macro. A macro is tested which has a nested (:key ...) parameter list in a required parameter position as well as in an optional position. * txr.1: Documented.
Diffstat (limited to 'tests/011')
-rw-r--r--tests/011/keyparams.tl9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/011/keyparams.tl b/tests/011/keyparams.tl
index e2f8baf2..189081d3 100644
--- a/tests/011/keyparams.tl
+++ b/tests/011/keyparams.tl
@@ -2,6 +2,8 @@
(defvarl v :v)
(defsymacro u (identity :u))
+(defvarl x :x)
+(defvarl y :y)
(mtest
[(lambda (:key))] nil
@@ -36,3 +38,10 @@
(test
(set (key-place :x 3 :y 4) 42) (3 4 42 t))
+
+(defmacro kp (r (:key -- (a v a-p) (b u b-p)) : ((:key -- (c x c-p) (d y d-p))))
+ ^'(r ,a ,a-p ,b ,b-p ,c ,c-p ,d ,d-p))
+
+(mtest
+ (kp :r ()) (r :v nil :u nil :x nil :y nil)
+ (kp 0 (:a 1 :b 2) (:d 3)) (r 1 t 2 t :x nil 3 t))