Hi, folx !
I have a question concerning class-variables in CLOS:
I have to build a class with one class-variable in it:
(defclass test ()
((cvar :initarg :cvar :initform 0.0 :allocation :class :reader foo)))
Now I want to define a subclass, in which the class-variable cvar
should be set to the value 10.0. One possibility would be to define
the subclass
(defclass test-sub ()
())
and then set the variable when creating the first instance:
(setf inst (make-instance 'test :cvar 10.0))
but I don't like this very much.
Is there a way to specify the new default-value for the cvar-variable
in the test-sub class directly in the definition of test-sub ?
Thanx in advance for your help. Please answer via mail 'cause I'm not
able to read this group frequently.
greetings,
Carsten Lutz
--
* Carsten Lutz, Rellingen, FRG / ···@malihh.hanse.de ( NeXTmail accepted ) *
* Voice : +49 4101 512493 Fax: +49 4101 27757 Traily : +49 4101 22306 *
In article <·····················@malihh.hanse.de>, ···@malihh.hanse.de (Carsten Lutz) writes:
>Hi, folx !
>
>I have a question concerning class-variables in CLOS:
>
>I have to build a class with one class-variable in it:
>
>(defclass test ()
> ((cvar :initarg :cvar :initform 0.0 :allocation :class :reader foo)))
>
>Now I want to define a subclass, in which the class-variable cvar
>should be set to the value 10.0. One possibility would be to define
>the subclass
>
>(defclass test-sub ()
> ())
>
>and then set the variable when creating the first instance:
>
>(setf inst (make-instance 'test :cvar 10.0))
>
>but I don't like this very much.
>
>Is there a way to specify the new default-value for the cvar-variable
>in the test-sub class directly in the definition of test-sub ?
>
>Thanx in advance for your help. Please answer via mail 'cause I'm not
>able to read this group frequently.
>
>greetings,
> Carsten Lutz
>
I don't know if this is any more elegant, but you can try this (I
haven't tested it, but it should work):
(defclass test ()
((cvar :initarg :cvar :allocation :class :reader foo))
(:default-initargs :cvar 0.0))
(defclass test-sub (test) ()
(:default-initargs :cvar 10.0))
Randy
--
Randy A. Coulman |
Department of Computational Science |
University of Saskatchewan | ·······@cs.Usask.ca
Saskatoon, SK S7N 0W0 | ·······@skaries.Usask.ca