Lisp HUG Maillist Archive

Preventing instance variable clashes in CLOS

Hello,

Is there an available compiler warning when a subclass redefines an instance variable on a CLOS object?
If not, would you recommend a way to avoid accidental bugs?

TIA.

Best Regards,
Camille


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: Preventing instance variable clashes in CLOS

On 25 Oct 2012, at 18:09, Camille Troillard wrote:

> 
> Hello,
> 
> Is there an available compiler warning when a subclass redefines an instance variable on a CLOS object?
> If not, would you recommend a way to avoid accidental bugs?

Not that I know of.  This is often intentional, of course, as in something like

(defclass animal ()
  ((legs :initform 'uncountably-many
         :initarg :legs
         :reader legs)))

(defclass mammal (animal)
  ((legs :initform 4
         :initarg :limbs
         :reader limbs)))

There probably are tricks you can do with the MOP.

The simplest approach if you want to avoid unintentional name clashes is to use the package system.

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:36 UTC