Subject: Re: Inherited shared slots
From: Erik Naggum <clerik@naggum.no>
Date: 1998/04/13
Newsgroups: comp.lang.lisp
Message-ID: <3101493995517947@naggum.no>


* Erann Gat
| Here's a puzzle for you CLOS and MOP wizards.

  I'll try to answer, anyway.

| Is there a way to have a slot variable that is inherited as a class
| allocated variable in the sub-class?

  sorry to be so elaborate, but do you mean as in this example:

(defclass foo ()
  ((zot :allocation :class)))

(defclass bar (foo)
  ())

  that

(eq (setf (slot-value (make-instance 'bar) 'zot) (cons nil nil))
    (slot-value (make-instance 'bar) 'zot))

  should yield T?

  if so, you're in luck, because this is already the specified behavior of
  shared slots, _unless_ you create a new slot with the same name.  here's
  what the HyperSpec says on this issue (7.5.3):

    A consequence of the allocation rule is that a shared slot can be
    shadowed.  For example, if a class C1 defines a slot named S whose
    value for the :allocation slot option is :class, that slot is
    accessible in instances of C1 and all of its subclasses.  However, if
    C2 is a subclass of C1 and also defines a slot named S, C1's slot is
    not shared by instances of C2 and its subclasses.  When a class C1
    defines a shared slot, any subclass C2 of C1 will share this single
    slot unless the defclass form for C2 specifies a slot of the same name
    or there is a superclass of C2 that precedes C1 in the class precedence
    list of C2 that defines a slot of the same name.

  hope this helps.

#:Erik
-- 
  religious cult update in light of new scientific discoveries:
  "when we cannot go to the comet, the comet must come to us."