[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] state of tinyclos ?
From: |
Alex Shinn |
Subject: |
Re: [Chicken-users] state of tinyclos ? |
Date: |
Fri, 24 Mar 2006 02:47:55 -0600 |
User-agent: |
Wanderlust/2.10.1 (Watching The Wheels) SEMI/1.14.6 (Maruoka) FLIM/1.14.6 (Marutamachi) APEL/10.6 Emacs/21.3 (i386-pc-linux-gnu) MULE/5.0 (SAKAKI) |
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