Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding :initform to inherited slot

5 views
Skip to first unread message

Jacek Generowicz

unread,
Jul 18, 2005, 10:11:22 AM7/18/05
to
The following code results in new instances of MY-CLASS acquiring a
default value of 'MY-INITFORM in a slot they inherit from their
superclass.

(in-package "LIBRARY")

(defclass library-class ()
((library-slot)))

(in-package "MY-PACKAGE")

(defclass my-class (library-class)
((added-slot)))


(defmethod shared-initialize :before ((my-class my-class)
slotnames
&rest initargs
&key &allow-other-keys)
(setf (slot-value my-class 'library::library-slot) 'my-initform))

What is the canonical way of achieving this effect? In particular, I
am bothered by having to access the internal symbol LIBRARY-SLOT.

Pascal Costanza

unread,
Jul 18, 2005, 10:20:57 AM7/18/05
to

If I understand you correctly, the following should do the trick:

(defclass library-class ()
((library-slot :initarg :library-slot)))

(defclass my-class (library-class)
((added-slot))
(:default-initargs :library-slot 'my-initform))

I think you have to provide some access to the internals of your library
class. Of course, you could also try to devise a new protocol for this:

(defgeneric init-library-slot (object))

(defmethod init-library-slot ((object library-class))
'library-initform)

(defmethod shared-initialize :before ((object library-class) ...)
(setf (slot-value object 'library-slot)
(init-library-slot object)))


Pascal

--
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/

Jacek Generowicz

unread,
Jul 18, 2005, 11:06:27 AM7/18/05
to
Pascal Costanza <p...@p-cos.net> writes:

> If I understand you correctly, the following should do the trick:
>
> (defclass library-class ()
> ((library-slot :initarg :library-slot)))
>
> (defclass my-class (library-class)
> ((added-slot))
> (:default-initargs :library-slot 'my-initform))

Duh! Of course. I've been away from CLOS for too long :-( Thanks.

> I think you have to provide some access to the internals of your
> library class.

Sorry, should have shown it in the first place: that :initarg is
already there in the superclass (and it's not mine, I'm just a
client).

0 new messages