From: Paolo Amoroso
Subject: Namespaces of class slot names and accessors
Date: 
Message-ID: <878ygk9tnw.fsf@plato.moon.paoloamoroso.it>
To which namespace do class slot names belong?  And slot accessors?

More specifically, I would like to know whether it is possible for
different classes--in the same package--to have slots with the same
names, such as:

  (defclass class1 ()
    ((same-slot :initarg :same-slot)))

  (defclass class2 ()
    ((same-slot :initarg :same-slot)))

or for different classes to have slots with the same accessor names:

  (defclass class1 ()
    ((class1-slot :initarg :class1-slot :accessor same-accessor)))

  (defclass class2 ()
    ((class2-slot :initarg :class2-slot :accessor same-accessor)))


Paolo
-- 
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film

From: Scott McKay
Subject: Re: Namespaces of class slot names and accessors
Date: 
Message-ID: <raOic.30059$IW1.1341220@attbi_s52>
"Paolo Amoroso" <·······@mclink.it> wrote in message
···················@plato.moon.paoloamoroso.it...
> To which namespace do class slot names belong?  And slot accessors?
>
> More specifically, I would like to know whether it is possible for
> different classes--in the same package--to have slots with the same
> names, such as:
>
>   (defclass class1 ()
>     ((same-slot :initarg :same-slot)))
>
>   (defclass class2 ()
>     ((same-slot :initarg :same-slot)))
>
> or for different classes to have slots with the same accessor names:
>
>   (defclass class1 ()
>     ((class1-slot :initarg :class1-slot :accessor same-accessor)))
>
>   (defclass class2 ()
>     ((class2-slot :initarg :class2-slot :accessor same-accessor)))
>

'same-accessor' is just the name of a generic function for
the slot's accessor method, so this will work.  However,
even though there is no enforcement, I think that you
should be sure that 'same-accessor' implements the
same sort of semantics for each class.

FWIW, when I share accessor names between multiple
classes, I first define generic functions for those accessors.

As for slot names, well, they're just names of symbols.
After the Dylan experience, slot names as distinct from
accessors seem like a mistake to me now.
From: Rainer Joswig
Subject: Re: Namespaces of class slot names and accessors
Date: 
Message-ID: <joswig-33EADC.16432525042004@news.fu-berlin.de>
In article <·······················@attbi_s52>,
 "Scott McKay" <···········@comcast.net> wrote:

> "Paolo Amoroso" <·······@mclink.it> wrote in message
> ···················@plato.moon.paoloamoroso.it...
> > To which namespace do class slot names belong?  And slot accessors?
> >
> > More specifically, I would like to know whether it is possible for
> > different classes--in the same package--to have slots with the same
> > names, such as:
> >
> >   (defclass class1 ()
> >     ((same-slot :initarg :same-slot)))
> >
> >   (defclass class2 ()
> >     ((same-slot :initarg :same-slot)))
> >
> > or for different classes to have slots with the same accessor names:
> >
> >   (defclass class1 ()
> >     ((class1-slot :initarg :class1-slot :accessor same-accessor)))
> >
> >   (defclass class2 ()
> >     ((class2-slot :initarg :class2-slot :accessor same-accessor)))
> >
> 
> 'same-accessor' is just the name of a generic function for
> the slot's accessor method, so this will work.  However,
> even though there is no enforcement, I think that you
> should be sure that 'same-accessor' implements the
> same sort of semantics for each class.
> 
> FWIW, when I share accessor names between multiple
> classes, I first define generic functions for those accessors.
> 
> As for slot names, well, they're just names of symbols.
> After the Dylan experience, slot names as distinct from
> accessors seem like a mistake to me now.

One thing one could do is to use an uninterned symbol
as the slot name, so you would be forced to
use an accessor to read/write the slot
(unless you have some introspective capability
to get the class slot-names).

(defclass foo () ((#:bar :accessor foo-bar :initform 0)))

Now (slot-value (make-instance 'foo) '#:bar) does not work,
since #:bar and another #:bar are not eql.
From: Tim Bradshaw
Subject: Re: Namespaces of class slot names and accessors
Date: 
Message-ID: <fbc0f5d1.0404260436.4d66f8df@posting.google.com>
Rainer Joswig <······@lispmachine.de> wrote in message news:<····························@news.fu-berlin.de>...

> 
> One thing one could do is to use an uninterned symbol
> as the slot name, so you would be forced to
> use an accessor to read/write the slot
> (unless you have some introspective capability
> to get the class slot-names).
> 
> (defclass foo () ((#:bar :accessor foo-bar :initform 0)))
> 
> Now (slot-value (make-instance 'foo) '#:bar) does not work,
> since #:bar and another #:bar are not eql.

I have a wrapper around DEFCLASS that lets you define various `magic'
kinds of slots - in particular slots which are private to a class -
like this.  You need slightly more than just using a gensym, because
using a gensym doesn't let you redefine the class easily (well, you
can redefine it, but it doesn't know that the slots are the same). 
I've never actually used the wrapper though, so for what I do at least
it didn't seem to be useful.

--tim
From: Kalle Olavi Niemitalo
Subject: Re: Namespaces of class slot names and accessors
Date: 
Message-ID: <87wu44q9oa.fsf@Astalo.kon.iki.fi>
Paolo Amoroso <·······@mclink.it> writes:

> More specifically, I would like to know whether it is possible for
> different classes--in the same package--to have slots with the same
> names, such as:
>
>   (defclass class1 ()
>     ((same-slot :initarg :same-slot)))
>
>   (defclass class2 ()
>     ((same-slot :initarg :same-slot)))

It is possible.  However, if you define a CLASS3 that has both
CLASS1 and CLASS2 as its superclasses, then each instance of
CLASS3 will have only one slot named SAME-SLOT, which may cause
conflicts.  If you know such a class won't be needed, there's no
problem.