[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
self and CLOS
- To: info-mcl@cambridge.apple.com
- Subject: self and CLOS
- From: jbk@world.std.com (Jeffrey B Kane)
- Date: Thu, 2 Jul 92 11:37:44 -0400
I have a question that ya'll may be able to help me with. I'm learning the
CLOS system (I've been programing in Object Pascal & C++ for some time), but a
few of it's fine points are seeming to escape me. The first is how you refer
to your "self". As an example here is a very simple class that represents a
graphic object which can be dragged, resized, and knows how to draw itself.
(defclass square-thing ()
((fTop :accessor top
:init-form 10
:init-arg :top)
(fLeft :accessor left
:init-form 10
:init-arg :left)
(fBottom :accessor bottom
:init-form 100
:init-arg :bottom)
(fRight :accessor right
:init-form 100
:init-arg :right))
OK, so far so good. Now I want to define a method which will be used for this
thing to draw itself on the screen each time. I wanted to define the method
so that the coordinates are optional, otherwise it just draws itself in it's
current place (as defined by the slots). My problem is, how do I specify the
default values of the &optional arguments without refering to a "self".
The following example is what I am trying (but is wrong):
(defmethod draw ((me square-thing) (wind view)
&optional (t (me top)) (l (me left))
(b (me bottom)) (r (me right)))
(paint-rect wind l t r b)
(frame-rect wind l t r b))
I don't want to have to kludge the lambda list with 0 (or neg) defaults (and
then test if they are zero or negative). There must be a way to do this correctly.
Jeffrey