From: Jacek Generowicz
Subject: Adding :initform to inherited slot
Date: 
Message-ID: <m2mzokyzjp.fsf@genera.local>
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.

From: Pascal Costanza
Subject: Re: Adding :initform to inherited slot
Date: 
Message-ID: <3k1s69Fsd2icU1@individual.net>
Jacek Generowicz wrote:
> 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.

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/
From: Jacek Generowicz
Subject: Re: Adding :initform to inherited slot
Date: 
Message-ID: <m2fyucywzw.fsf@genera.local>
Pascal Costanza <ยทยท@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).