From: Marco Baringer
Subject: CLOS style: default-initargs vs. multiple initforms
Date: 
Message-ID: <m2r7nopi49.fsf@bese.it>
Assuming i have a class foo:

(defclass foo ()
  ((a :initform nil :initform :a)))

I'd like to sub class foo and change the default value of the slot A
to T, afaict there are two ways to do this:

(defclass sub-foo (foo)
  ()
  (:default-initargs :a t))

or

(defclass sub-foo (foo)
  ((a :initform t)))

Other than 1) the extra direct-slot-definition in the second case and
2) the fact that the first only works when foo's A slot has an
initarg, is there any difference between these two? which style do
people prefer? I'm leaning towards the first as it makes very clear
that the slot we're refering to is foo's A and not some new and
different A.

-- 
-Marco
Ring the bells that still can ring.
Forget your perfect offering.
There is a crack in everything.
That's how the light gets in.
     -Leonard Cohen

From: Pascal Costanza
Subject: Re: CLOS style: default-initargs vs. multiple initforms
Date: 
Message-ID: <clg7qh$9j7$1@newsreader2.netcologne.de>
Marco Baringer wrote:
> Assuming i have a class foo:
> 
> (defclass foo ()
>   ((a :initform nil :initform :a)))
> 
> I'd like to sub class foo and change the default value of the slot A
> to T, afaict there are two ways to do this:
> 
> (defclass sub-foo (foo)
>   ()
>   (:default-initargs :a t))
> 
> or
> 
> (defclass sub-foo (foo)
>   ((a :initform t)))

The second alternative may break when someone changes slot a's 
allocation in foo to :class.


Pascal

-- 
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
From: Kenneth Tilton
Subject: Re: CLOS style: default-initargs vs. multiple initforms
Date: 
Message-ID: <2004102414270250073%ktilton@nycrrcom>
On 2004-10-24 05:42:30 -0400, "Marco Baringer" <ยทยท@bese.it> said:

> 
> Assuming i have a class foo:
> 
> (defclass foo ()
>   ((a :initform nil :initform :a)))
> 
> I'd like to sub class foo and change the default value of the slot A
> to T, afaict there are two ways to do this:
> 
> (defclass sub-foo (foo)
>   ()
>   (:default-initargs :a t))
> 
> or
> 
> (defclass sub-foo (foo)
>   ((a :initform t)))
> 
> Other than 1) the extra direct-slot-definition in the second case and
> 2) the fact that the first only works when foo's A slot has an
> initarg, is there any difference between these two? which style do
> people prefer? I'm leaning towards the first as it makes very clear
> that the slot we're refering to is foo's A and not some new and
> different A.

I was all over the map on this issue until a hard-to-find bug made me 
notice what I think is a decisive factor: any default-initarg, no 
matter how high up the class inheritance list will trump any initform, 
no matter how specific to a subclass.

So there really is no choice in the matter other than consistently to 
author default values for an inherited slot via default-initargs. The 
initform can be used in the class declaring the slot originally for 
convenience. This comes a cropper only if during refactoring one 
somewhow ends up with a new superclass also "originating" the same slot 
and then some newly-inherited intermediate class specifying a 
default-initarg, but I would expect the refactoring to chop the slot 
from what was the original class to originate the slot. If you know 
what I mean. :)

kenny