At Mon, 20 Mar 2006 11:43:02 -0600, Rick Taube wrote:
> 
> i am curious as to the current state of chicken's tinyclos  
> implementation: does it allow slot descriptions with  :init- 
> keywords, :init-forms and :accessors yet like gauche, guile and stklos?

init-value: and init-thunk: could be easily supported with the MOP:

(define-class <slot-initializer> (<class>) ())

(define initialize-slots-with-defaults
  (let ([not-there (gensym)])
    (lambda (object initargs)
      (##sys#check-list initargs 'initialize-slots)
      (for-each
       (lambda (slot)
         (let* ([name (car slot)]
                [value  (quick-getl initargs name not-there)] )
           (if (eq? value not-there)
             (when (pair? (cdr slot))
               (let lp ((key (car slot)) (ls (cdr slot)))
                 (when (pair? ls)
                   (cond
                     ((eq? key init-value:) (slot-set! object name (car ls)))
                     ((eq? key init-thunk:) (slot-set! object name ((car ls))))
                     (else (lp (car ls) (cdr ls)))))))
             (slot-set! object name value))))
       (class-slots (class-of object))))))

(define-method (initialize (object <slot-initializer>) initargs)
  (call-next-method)
  (initialize-slots-with-defaults object initargs))

(define-class <foo> (<slot-initializer>)
  ((bar init-value: 1)
   (baz init-value: 2)))

(slot-ref (make <foo>) 'bar) => 1
(slot-ref (make <foo> 'bar 3) 'bar) => 3

init-form: would need some help from the define-class macro to
thunkify the form and translate it to init-thunk:.

-- 
Alex


_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to