From: Pedro Kroger
Subject: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <1179239087.118123.42980@w5g2000hsg.googlegroups.com>
Hi,

suppose I have a class with 6 slots, is it possible to inherit that
class except for one slot? for instance, if I have foo like this:

(defclass foo ()
   (a1 a2 a3 a5 a5 a6))

and bar is a subclass of foo:

(defclass bar (foo)
  ...)

foo will have, of course, the 6 slots, but I want bar to have all
slots of foo except a6. I don't have any specific use for this, I'm
just thinking if this is possible or not. (I don't even know if this
is good practice)

Pedro Kroger

From: Tayssir John Gabbour
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <1179245659.421543.192770@u30g2000hsc.googlegroups.com>
On May 15, 4:24 pm, Pedro Kroger <············@gmail.com> wrote:
> suppose I have a class with 6 slots, is it possible to inherit that
> class except for one slot? for instance, if I have foo like this:
>
> (defclass foo ()
>    (a1 a2 a3 a5 a5 a6))
>
> and bar is a subclass of foo:
>
> (defclass bar (foo)
>   ...)
>
> foo will have, of course, the 6 slots, but I want bar to have all
> slots of foo except a6. I don't have any specific use for this, I'm
> just thinking if this is possible or not. (I don't even know if this
> is good practice)

Well, I believe you can do something like:


(defclass foo ()
  (a1 a2 a3 a4 a5
   (a6 :inherit? nil))
  (:metaclass conditional-inheritance-class))

;; Instances will inherit only slots a1-a5. Not a6.
(defclass bar (foo)
  ()
  (:metaclass conditional-inheritance-class))


Full implementation at:
http://paste.lisp.org/display/41243


Tayssir
--
[Disclaimer -- I have almost never used the MOP seriously.]
From: Ken Tilton
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <8uj2i.4966$m86.176@newsfe12.lga>
Pedro Kroger wrote:
> Hi,
> 
> suppose I have a class with 6 slots, is it possible to inherit that
> class except for one slot? for instance, if I have foo like this:
> 
> (defclass foo ()
>    (a1 a2 a3 a5 a5 a6))
> 
> and bar is a subclass of foo:
> 
> (defclass bar (foo)
>   ...)
> 
> foo will have, of course, the 6 slots, but I want bar to have all
> slots of foo except a6. I don't have any specific use for this, I'm
> just thinking if this is possible or not. (I don't even know if this
> is good practice)

My non-response response:

God, how poetic would it be if no one responded to this!

kt

-- 
http://www.theoryyalgebra.com/

"Algebra is the metaphysics of arithmetic." - John Ray

"As long as algebra is taught in school,
there will be prayer in school." - Cokie Roberts

"Stand firm in your refusal to remain conscious during algebra."
    - Fran Lebowitz

"I'm an algebra liar. I figure two good lies make a positive."
    - Tim Allen
From: Joe Marshall
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <1179252973.463056.247920@h2g2000hsg.googlegroups.com>
On May 15, 7:24 am, Pedro Kroger <············@gmail.com> wrote:
> Hi,
>
> suppose I have a class with 6 slots, is it possible to inherit that
> class except for one slot? for instance, if I have foo like this:
>
> (defclass foo ()
>    (a1 a2 a3 a5 a5 a6))
>
> and bar is a subclass of foo:
>
> (defclass bar (foo)
>   ...)
>
> foo will have, of course, the 6 slots, but I want bar to have all
> slots of foo except a6. I don't have any specific use for this, I'm
> just thinking if this is possible or not. (I don't even know if this
> is good practice)

This is an instance of `subtractive inheritance'.  CLOS doesn't
support it by default (but you can always change that).

It's probably not a good idea because if BAR inherits from FOO, then a
BAR object should be usable as a FOO.  If the BAR object doesn't have
an a6 slot, then it is likely to not work for certain methods.
From: Jules
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <1179257645.002152.51650@p77g2000hsh.googlegroups.com>
On May 15, 8:16 pm, Joe Marshall <··········@gmail.com> wrote:
> On May 15, 7:24 am, Pedro Kroger <············@gmail.com> wrote:
>
>
>
> > Hi,
>
> > suppose I have a class with 6 slots, is it possible to inherit that
> > class except for one slot? for instance, if I have foo like this:
>
> > (defclass foo ()
> >    (a1 a2 a3 a5 a5 a6))
>
> > and bar is a subclass of foo:
>
> > (defclass bar (foo)
> >   ...)
>
> > foo will have, of course, the 6 slots, but I want bar to have all
> > slots of foo except a6. I don't have any specific use for this, I'm
> > just thinking if this is possible or not. (I don't even know if this
> > is good practice)
>
> This is an instance of `subtractive inheritance'.  CLOS doesn't
> support it by default (but you can always change that).
>
> It's probably not a good idea because if BAR inherits from FOO, then a
> BAR object should be usable as a FOO.  If the BAR object doesn't have
> an a6 slot, then it is likely to not work for certain methods.

Consider a rectangle inheriting from polygon. You want to keep a list
of points in polygon, but you want width/height, x/y slots in
rectangle. You define an accessor method `points` that computes the
list of points for rectangles.

Jules
From: Dan Bensen
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <f2d59b$8q7$1@wildfire.prairienet.org>
Jules wrote:
> Consider a rectangle inheriting from polygon. You want to keep a list
> of points in polygon, but you want width/height, x/y slots in
> rectangle. You define an accessor method `points` that computes the
> list of points for rectangles.

Since the implementations (slots) are so different, it doesn't make
much sense to derive one from the other.  They might as well inherit
separately from an abstract polygon class that specifies accessor
methods but not the data representation.

-- 
Dan
www.prairienet.org/~dsb/
From: Barry Margolin
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <barmar-32CBD1.00542516052007@comcast.dca.giganews.com>
In article <············@wildfire.prairienet.org>,
 Dan Bensen <··········@cyberspace.net> wrote:

> Jules wrote:
> > Consider a rectangle inheriting from polygon. You want to keep a list
> > of points in polygon, but you want width/height, x/y slots in
> > rectangle. You define an accessor method `points` that computes the
> > list of points for rectangles.
> 
> Since the implementations (slots) are so different, it doesn't make
> much sense to derive one from the other.  They might as well inherit
> separately from an abstract polygon class that specifies accessor
> methods but not the data representation.

Which is a notion that CLOS doesn't make explicit, like some other OO 
languages do.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Ken Tilton
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <6px2i.2984$Pa5.1477@newsfe12.lga>
Barry Margolin wrote:
> In article <············@wildfire.prairienet.org>,
>  Dan Bensen <··········@cyberspace.net> wrote:
> 
> 
>>Jules wrote:
>>
>>>Consider a rectangle inheriting from polygon. You want to keep a list
>>>of points in polygon, but you want width/height, x/y slots in
>>>rectangle.

Because the sides of all rectangles are parallel to the axes? Oops. Oh, 
OK, now you want to add a rotation. But..

I am also interested in knowing where x/y lies relative to the larger 
rectangle? top-left, ala the convention of many coordinate systems? 
bottom-left ala OpenGL? Arbitrary, ala my superior coordinate systems 
(which perforce need more than width and height, viz, four relative 
offsets from the x/y "origin")?

Let me help: fine, create a Rectangle class. Give it slots for an x/y 
and left,top,right,bottom offsets from x and y as appropriate. Now give 
it a rotation. Now make the vertices (oops!) a function of those highly 
special case-specific parameters. ie, You /do/ need the vertices slot.

kzo

-- 
http://www.theoryyalgebra.com/

"Algebra is the metaphysics of arithmetic." - John Ray

"As long as algebra is taught in school,
there will be prayer in school." - Cokie Roberts

"Stand firm in your refusal to remain conscious during algebra."
    - Fran Lebowitz

"I'm an algebra liar. I figure two good lies make a positive."
    - Tim Allen
From: John Thingstad
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <op.tseq46oppqzri1@pandora.upc.no>
On Wed, 16 May 2007 08:18:46 +0200, Ken Tilton <···········@optonline.net>  
wrote:

>
>
> Barry Margolin wrote:
>> In article <············@wildfire.prairienet.org>,
>>  Dan Bensen <··········@cyberspace.net> wrote:
>>
>>> Jules wrote:
>>>
>>>> Consider a rectangle inheriting from polygon. You want to keep a list
>>>> of points in polygon, but you want width/height, x/y slots in
>>>> rectangle.
>
> Because the sides of all rectangles are parallel to the axes? Oops. Oh,  
> OK, now you want to add a rotation. But..
>
> I am also interested in knowing where x/y lies relative to the larger  
> rectangle? top-left, ala the convention of many coordinate systems?  
> bottom-left ala OpenGL? Arbitrary, ala my superior coordinate systems  
> (which perforce need more than width and height, viz, four relative  
> offsets from the x/y "origin")?
>
> Let me help: fine, create a Rectangle class. Give it slots for an x/y  
> and left,top,right,bottom offsets from x and y as appropriate. Now give  
> it a rotation. Now make the vertices (oops!) a function of those highly  
> special case-specific parameters. ie, You /do/ need the vertices slot.
>
> kzo
>

Rotation is better handled by a transformation.
Angle is not a property of a rectangle.
The same goes for offset and scale.
(the relative size of the sides IS a property of a rectangle.)
It only makes sense in relation to a coordinate system.
So do you hard-code the coordinate system into the model?
For screen coordinates you might want this. After all it relates
to a physical device with actual properties.
For a plot it does not necessarily.
In fact you might need several representations for efficiency.
A abstract coordinate model and physical coordinate model and perhaps
a cache for efficient repaint.

(Yeah.. Wrote a plotting package a few years back.)

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Ken Tilton
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <pfF2i.12$1G7.7@newsfe12.lga>
John Thingstad wrote:
> On Wed, 16 May 2007 08:18:46 +0200, Ken Tilton 
> <···········@optonline.net>  wrote:
> 
>>
>>
>> Barry Margolin wrote:
>>
>>> In article <············@wildfire.prairienet.org>,
>>>  Dan Bensen <··········@cyberspace.net> wrote:
>>>
>>>> Jules wrote:
>>>>
>>>>> Consider a rectangle inheriting from polygon. You want to keep a list
>>>>> of points in polygon, but you want width/height, x/y slots in
>>>>> rectangle.
>>
>>
>> Because the sides of all rectangles are parallel to the axes? Oops. 
>> Oh,  OK, now you want to add a rotation. But..
>>
>> I am also interested in knowing where x/y lies relative to the larger  
>> rectangle? top-left, ala the convention of many coordinate systems?  
>> bottom-left ala OpenGL? Arbitrary, ala my superior coordinate systems  
>> (which perforce need more than width and height, viz, four relative  
>> offsets from the x/y "origin")?
>>
>> Let me help: fine, create a Rectangle class. Give it slots for an x/y  
>> and left,top,right,bottom offsets from x and y as appropriate. Now 
>> give  it a rotation. Now make the vertices (oops!) a function of those 
>> highly  special case-specific parameters. ie, You /do/ need the 
>> vertices slot.
>>
>> kzo
>>
> 
> Rotation is better handled by a transformation.

A rotation is a transformation. Anyway, you still need the information 
that is the specific transformation to define a specific instance.

> Angle is not a property of a rectangle.
> The same goes for offset and scale.

I think you are not talking about instances of rectangles, and this 
discussion is about how much information a class needs to represent 
instances of that class. I am picturing a figure composed of six 
rectangles. I will only give you their height. (Why store the width? It 
is always one, right?)

    (2 2 2 4 .5 .5)

> (Yeah.. Wrote a plotting package a few years back.)

Plot that. An ascii diagram will do.

kt


-- 
http://www.theoryyalgebra.com/

"Algebra is the metaphysics of arithmetic." - John Ray

"As long as algebra is taught in school,
there will be prayer in school." - Cokie Roberts

"Stand firm in your refusal to remain conscious during algebra."
    - Fran Lebowitz

"I'm an algebra liar. I figure two good lies make a positive."
    - Tim Allen
From: John Thingstad
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <op.tsdvtvempqzri1@pandora.upc.no>
On Tue, 15 May 2007 21:34:05 +0200, Jules <···········@gmail.com> wrote:

>
> Consider a rectangle inheriting from polygon. You want to keep a list
> of points in polygon, but you want width/height, x/y slots in
> rectangle. You define an accessor method `points` that computes the
> list of points for rectangles.
>
> Jules
>

I have some questions about the taxonomy.
How about shape and polygon and rectangle both inheriting from it?
It just seems to me that your inheritance may not be the most efficient.
The reason you get functions that have no meaning may be that
another decomposition makes more sense.

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Jules
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <1179261953.431780.176370@o5g2000hsb.googlegroups.com>
On May 15, 9:45 pm, "John Thingstad" <··············@chello.no> wrote:
> On Tue, 15 May 2007 21:34:05 +0200, Jules <···········@gmail.com> wrote:
>
> > Consider a rectangle inheriting from polygon. You want to keep a list
> > of points in polygon, but you want width/height, x/y slots in
> > rectangle. You define an accessor method `points` that computes the
> > list of points for rectangles.
>
> > Jules
>
> I have some questions about the taxonomy.
> How about shape and polygon and rectangle both inheriting from it?
> It just seems to me that your inheritance may not be the most efficient.
> The reason you get functions that have no meaning may be that
> another decomposition makes more sense.

Which functions? The accessor still makes sense, but the internal
representation has changed. Representations often have to change when
creating a more specialized version of something. Say you're using
polygons and rectangles to draw vector graphics. You want to change
the representation of rectangle and the implementation of draw-on-
screen for rectangle for efficiency. On the other hand you still want
to be able to use utility methods that don't need to be fast.

(defmethod points ((r rectangle))
  (with-slots (x y width height) r
    (list
     (make-point x y)
     (make-point (+ x width) y)
     ...))

I think rectangle should be a subclass of polygon. A rectangle is a
special polygon, and you could have used the representation of polygon
(a list of points), but for some reason you want to use another
representation. No-one will notice because the interface is the same
either way.

>
> --
> Using Opera's revolutionary e-mail client:http://www.opera.com/mail/
From: John Thingstad
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <op.tsd1azqkpqzri1@pandora.upc.no>
On Tue, 15 May 2007 22:45:53 +0200, Jules <···········@gmail.com> wrote:

>
> I think rectangle should be a subclass of polygon. A rectangle is a
> special polygon, and you could have used the representation of polygon
> (a list of points), but for some reason you want to use another
> representation. No-one will notice because the interface is the same
> either way.
>

No. A rectangle is a polygon. Not a type of polygon.
Just like a circle is a elipse with a = b = r
So to me it is a object instance.
A rectangle is a instance of polygon with happens to have 4 sides.
Rectangles in graphics happen sufficiently often in windows apps that
it makes sense to optimize the implementation heavely. That is why I
would have a seperate rectangle class. Say you want to know if the mouse
is withing a rectangle. In windows programming that happens all the time.
It is far more difficult and slow to determine this for a general polygon.
Also it is less interesting.


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Timofei Shatrov
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <464ac182.14018727@news.readfreenews.net>
On Tue, 15 May 2007 23:43:37 +0200, "John Thingstad" <··············@chello.no>
tried to confuse everyone with this message:

> Say you want to know if the mouse=
>
>is withing a rectangle. In windows programming that happens all the time=
>.
>It is far more difficult and slow to determine this for a general polygo=
>n.

It is quite easy for convex polygon though. In my game "Urban Warfare" [1] each
rectangle is an instance of convex class. However the game works with affine
geometry, so the very notion of rectangle is undefined...

[1] http://common-lisp.net/project/lifp/uwar.htm

-- 
|Don't believe this - you're not worthless              ,gr---------.ru
|It's us against millions and we can't take them all... |  ue     il   |
|But we can take them on!                               |     @ma      |
|                       (A Wilhelm Scream - The Rip)    |______________|
From: Pascal Costanza
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <5au017F2p569sU1@mid.individual.net>
Pedro Kroger wrote:
> Hi,
> 
> suppose I have a class with 6 slots, is it possible to inherit that
> class except for one slot? for instance, if I have foo like this:
> 
> (defclass foo ()
>    (a1 a2 a3 a5 a5 a6))
> 
> and bar is a subclass of foo:
> 
> (defclass bar (foo)
>   ...)
> 
> foo will have, of course, the 6 slots, but I want bar to have all
> slots of foo except a6. I don't have any specific use for this, I'm
> just thinking if this is possible or not. (I don't even know if this
> is good practice)

In order to disappoint Ken, here is a response:

The CLOS designers actually discussed two more :allocation options for 
slots, :dynamic and :none. :dynamic would have enabled slots that don't 
use up any memory if they are unbound, and :none would have enabled 
removing slots that would otherwise be potentially inherited from 
superclasses.

Both were dropped. Apparently, the reasons were that :dynamic doesn't 
actually add substantial new functionality and that :none makes 
inheritance of slot options a lot more complicated.

Here is a relevant quote by David Moon:

"In Flavors, we spent a lot of time some years ago discovering that that
style doesn't work very well.  It worked out a lot better to split the
superclass into separate modules and then inherit whichever ones are
wanted.  I haven't thought about it real deeply, but I think the Common
Lisp object system is similar enough to Flavors that it will work out
the same way.

If you believe this, maybe we should get rid of :allocation :none, since
it seems to make slot inheritance a lot harder to document and to
understand."


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Ken Tilton
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <Cjk2i.2$8p6.1@newsfe12.lga>
Pascal Costanza wrote:
> Pedro Kroger wrote:
> 
>> Hi,
>>
>> suppose I have a class with 6 slots, is it possible to inherit that
>> class except for one slot? for instance, if I have foo like this:
>>
>> (defclass foo ()
>>    (a1 a2 a3 a5 a5 a6))
>>
>> and bar is a subclass of foo:
>>
>> (defclass bar (foo)
>>   ...)
>>
>> foo will have, of course, the 6 slots, but I want bar to have all
>> slots of foo except a6. I don't have any specific use for this, I'm
>> just thinking if this is possible or not. (I don't even know if this
>> is good practice)
> 
> 
> In order to disappoint Ken, here is a response:

What you do not know is that my remarks were meant mainly to stop you 
specifically from responding, and that I guessed you would not be able 
to stop yourself from responding anyway. ie, "delight" is closer to the 
mark.

> Here is a relevant quote by David Moon:
> 
> "It worked out a lot better to split the
> superclass into separate modules and then inherit whichever ones are
> wanted. "

Well surprise-frickin-surprise.

kzo

-- 
http://www.theoryyalgebra.com/

"Algebra is the metaphysics of arithmetic." - John Ray

"As long as algebra is taught in school,
there will be prayer in school." - Cokie Roberts

"Stand firm in your refusal to remain conscious during algebra."
    - Fran Lebowitz

"I'm an algebra liar. I figure two good lies make a positive."
    - Tim Allen
From: Pascal Bourguignon
Subject: Re: Is it possible to remove a slot when inheriting?
Date: 
Message-ID: <87bqgmghzu.fsf@thalassa.lan.informatimago.com>
Pedro Kroger <············@gmail.com> writes:

> Hi,
>
> suppose I have a class with 6 slots, is it possible to inherit that
> class except for one slot? for instance, if I have foo like this:
>
> (defclass foo ()
>    (a1 a2 a3 a5 a5 a6))
>
> and bar is a subclass of foo:
>
> (defclass bar (foo)
>   ...)
>
> foo will have, of course, the 6 slots, but I want bar to have all
> slots of foo except a6. I don't have any specific use for this, I'm
> just thinking if this is possible or not. (I don't even know if this
> is good practice)

If not all foo have a a6, then a6 shouldn't be in foo.

(defclass foo ()
  (a1 a2 a3 a4 a5))

(defclass foo-with-a6 (foo)
  (a6))

(defclass bar (foo)
  ...)



Otherwise, since slots are usually accessed thru accessors (instead of
directly with slot-value), you can always write:

(defmethod a6 ((self bar)) (error "Cannot read a a6 in a bar"))
(defmethod (setf a6) (value (self bar)) (error "Cannot write a a6 into a bar"))

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.