diff options
-rw-r--r-- | share/txr/stdlib/defset.tl | 11 | ||||
-rw-r--r-- | txr.1 | 17 |
2 files changed, 22 insertions, 6 deletions
diff --git a/share/txr/stdlib/defset.tl b/share/txr/stdlib/defset.tl index 3fd8de2e..521260ba 100644 --- a/share/txr/stdlib/defset.tl +++ b/share/txr/stdlib/defset.tl @@ -67,10 +67,11 @@ (with-gensyms (getter setter) ^(defplace (,name ,*params) body (,getter ,setter - (let* ((gpf-pairs (append (mapcar (op list (gensym)) - (list ,*fixpars)))) + (let* ((gpf-pairs (mapcar (op list (gensym)) (list ,*fixpars))) (gpr-pairs (if ',restpar - (mapcar (op list (gensym)) ,restpar))) + (if (consp ,restpar) + (mapcar (op list (gensym)) ,restpar) + (list (list (gensym) ,restpar))))) (ext-pairs (mapcar (op list (gensym)) (list ,*extsyms))) (pgens [mapcar car gpf-pairs]) (rgens [mapcar car gpr-pairs]) @@ -81,7 +82,9 @@ ,*(zip ',extsyms (mapcar (ret ^',@1) egens)) ,*(if gpr-pairs - ^((,',restpar ',rgens)))) + (if (consp ,restpar) + ^((,',restpar ',rgens)) + ^((,',restpar ',(car rgens)))))) (macrolet ((,,getter () ,',getform) (,,setter (,',newval) ,',setform)) ,body)) @@ -34623,8 +34623,21 @@ the two trailing parameters corresponding to the rest parameter Syntactic places defined by .code defset -may not use improper syntax such as -.codn "(set (g 1 2 . 3) v)" . +that have a rest parameter may be invoked with improper syntax such as +.codn "(set (g x y . z) v)" . +In this situation, that rest parameter will be bound to the name of +a temporary variable which holds the value of +.code z +rather than to a list of temporary variable names holding the values +of trailing expressions. +The +.code get-form +and +.code set-form +must be prepared for this situation. In particular, the rest parameter's value +is an atom, then it cannot be spliced in the backquote syntax, except at the +last position of a list. + Although syntactic places defined by .code defset perform macro-parameter-like destructuring of the place form, binding |