From: ··········@neodesic.com
Subject: defmethod on classes
Date: 
Message-ID: <6ubr2f$boi$1@nnrp1.dejanews.com>
I think I must be missing something obvious, but is there a way to write
methods on standard classes?

For example, of course I can do:

(defclass my-class () ())

(defmethod id ((self my-class)) "a my-class instance")

Is there a way to do something like:

(defmethod id ((self (find-class 'my-class))) "the class itself")

So:

(id (make-instance 'my-class)) => "a my-class instance"

(id (find-class 'my-class)) => "the class itself"

- Will Fitzgerald

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

From: Barry Margolin
Subject: Re: defmethod on classes
Date: 
Message-ID: <qefO1.26$7h2.565631@burlma1-snr1.gtei.net>
In article <············@nnrp1.dejanews.com>,  <··········@neodesic.com> wrote:
>Is there a way to do something like:
>
>(defmethod id ((self (find-class 'my-class))) "the class itself")

(defmethod id ((self (eql (find-class 'my-class))))
  "the class itself")

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
From: ··········@neodesic.com
Subject: Re: defmethod on classes
Date: 
Message-ID: <6ug6ib$ull$1@nnrp1.dejanews.com>
In article <···················@burlma1-snr1.gtei.net>,
  Barry Margolin <······@bbnplanet.com> wrote:
> In article <············@nnrp1.dejanews.com>,  <··········@neodesic.com>
wrote:
> >Is there a way to do something like:
> >
> >(defmethod id ((self (find-class 'my-class))) "the class itself")
>
> (defmethod id ((self (eql (find-class 'my-class))))
>   "the class itself")
>
>

I realize that I've had the wrong model in my head. What I wanted was
something like this to work:

(defmethod id ((self (find-class 'my-class))) "my class") ; bogus!
(defclass my-subclass (my-class) ())
(id (make-instance 'my-subclass)) => "my class")

I was thinking the relationship between (find-class 'my-class) and
(find-class 'my-subclass) was the same as between (find-class 'my-class) and
(make-instance 'my-subclass), which it isn't, of course.

The 'programming pattern' I'm now using is to pass a class prototype to the
method:

(defclass my-class () ())
(defclass my-subclass (my-class) ())
(defmethod id ((self my-class)) "my-class")
(id (class-prototype (find-class 'my-subclass))) => "my-class")

Question: Is CLASS-PROTOTYPE, part of the Metaobject Protocol, typically
defined in the various Common Lisp implmentations? (I'm using MCL 4.x, where
it is defined)

Will Fitzgerald

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
From: Rainer Joswig
Subject: Re: defmethod on classes
Date: 
Message-ID: <joswig-2509981645070001@pbg3.lavielle.com>
In article <············@nnrp1.dejanews.com>, ··········@neodesic.com wrote:

> Question: Is CLASS-PROTOTYPE, part of the Metaobject Protocol, typically
> defined in the various Common Lisp implmentations? (I'm using MCL 4.x, where
> it is defined)

Genera has clos:class-prototype .
From: Vassili Bykov
Subject: Re: defmethod on classes
Date: 
Message-ID: <6ughkk$a7m$1@nnrp1.dejanews.com>
In article <············@nnrp1.dejanews.com>,
  ··········@neodesic.com wrote:
> [...]
> The 'programming pattern' I'm now using is to pass a class prototype to the
> method:
>
> (defclass my-class () ())
> (defclass my-subclass (my-class) ())
> (defmethod id ((self my-class)) "my-class")
> (id (class-prototype (find-class 'my-subclass))) => "my-class")

Ooh boy.  I'll try to reiterate what you want to do in plain English.  You
want the same method of a generic function ID to be invoked when the function
is applied to the class MY-CLASS or any of its subclasses.  That is, the
argument is supposed to be a class metaobject itself, not a class instance. 
Is that it?

You would do that as

  (defclass my-metaclass (standard-class) ())

  (defclass my-class ()
    ()
    (:metaclass my-metaclass))

  (defclass my-subclass (my-class)
     ()
     (:metaclass my-metaclass))

  (defmethod id ((class-metaobject standard-class))
    "standard class")

  (defmethod id ((class-metaobject my-metaclass))
    "my class")

And then you can do

  (id (find-class 'my-class))    => "my class"
  (id (find-class 'my-subclass)) => "my class"
  (id (find-class 'standard-object)) => "standard class"

> Question: Is CLASS-PROTOTYPE, part of the Metaobject Protocol, typically
> defined in the various Common Lisp implmentations?

No, CLASS-PROTOTYPE is not even part of the MOP if we take AMOP for a de-facto
standard.

--Vassili

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
From: Vassili Bykov
Subject: Re: defmethod on classes
Date: 
Message-ID: <6uh6qk$vme$1@nnrp1.dejanews.com>
In article <············@nnrp1.dejanews.com>, I wrote:
> No, CLASS-PROTOTYPE is not even part of the MOP if we take AMOP for a de-facto
> standard.

Sorry, it is in AMOP after all.

--Vassili

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
From: Howard R. Stearns
Subject: Re: defmethod on classes
Date: 
Message-ID: <36123CAE.C50BC222@elwood.com>
··········@neodesic.com wrote:
> ...
> Question: Is CLASS-PROTOTYPE, part of the Metaobject Protocol, typically
> defined in the various Common Lisp implmentations? (I'm using MCL 4.x, where
> it is defined)
> 
> Will Fitzgerald

The CLOS MOP spec is at http://www.elwood.com/alu/mop/index.html

As is often pointed out, though, just reading the spec is no subistite
for reading "The Art of the Metaobject Protocol" (AMOP).  The ALU link,
above, also gives information about AMOP and related books and
activities.