From 2cda9b946d701faa308b0915c83ea48fb94d94af Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 11 Oct 2022 23:05:16 -0700 Subject: structs: optional init-exprs now useful in :delegate * stdlib/struct.tl (:delegate): Handle the two-element form of the optional parameter, which specifies the usual initializing expression for the default value. This is just passed through as-is to the generated method. Diagnose if the three-element form occurs. * tests/012/oop.tl: Some new tests. * txr.1: Documented. --- stdlib/struct.tl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'stdlib/struct.tl') diff --git a/stdlib/struct.tl b/stdlib/struct.tl index d373c330..10b07710 100644 --- a/stdlib/struct.tl +++ b/stdlib/struct.tl @@ -427,9 +427,19 @@ (pp (new (fun-param-parser (cdr params) form))) (opt pp.(opt-syms)) (args (append pp.req opt pp.rest))) - ^((:method ,meth-name (,obj ,*pp.req - ,*(if opt (cons : (mapcar (lop list :) opt))) - ,*pp.rest) + ^((:method ,meth-name + (,obj ,*pp.req + ,*(if opt + (cons : (collect-each ((o pp.opt)) + (tree-case o + ((sym) ^(,sym :)) + ((sym init) o) + ((sym init sym-p) + (compile-error form + "~s: three-element optional \ \ + parameter ~s not supported" + o)))))) + ,*pp.rest) (qref ,delegate-expr (,target-method ,*args)))))) (define-struct-clause :mass-delegate (:form form self-var delegate-expr -- cgit v1.2.3