From: Will Hartung
Subject: Class methods in CLOS?
Date: 
Message-ID: <vfr750EB4Kxo.MHr@netcom.com>
Are there such beasts as Class Methods in CLOS?

I know that there are Class Variables, and I guess that there are
methods if I just specialize on my class:

(defmethod class-method ((the-class my-class))
  (this that the-other))

But can I access Class slots without an actual instance of the class
existing?

Is there a way to something like:

(defclass my-class ()
  ((my-class-variable :allocation :class :initform "Read Me")))

(slot-value (find-class 'my-class) 'my-class-variable)

(The previous doesn't work, as I'm sure you can imagine).

Without dramatic surgery? (i.e. minimal MOP fun, hopefully)

Subclassing STANDARD-CLASS seems like the thing to do, but it seems a
touch overkill, as well as other potentially bad ramifications.

All I really want to do is assign a "Human Readable" name to a class,
besides just the symbol-print-string. I could just create an a-list of
classes and strings, but I was kinda hoping that I could do it within
the class somehow.

I can just do something like:

(slot-value (make-instance 'my-class) 'my-class-variable)

But, then I'm creating disposable objects for all the wrong reason,
maybe.

Anyway, wisdom appreciated (even if not necesarily followed :-))

(It seems making a generic function would be the hot tip at this
point, by my reckoning).

-- 
Will Hartung - Rancho Santa Margarita. It's a dry heat. ······@netcom.com
1990 VFR750 - VFR=Very Red    "Ho, HaHa, Dodge, Parry, Spin, HA! THRUST!"
1993 Explorer - Cage? Hell, it's a prison.                    -D. Duck

From: Will Hartung
Subject: Re: Class methods in CLOS?
Date: 
Message-ID: <vfr750EB69ns.2vK@netcom.com>
····@merle.acns.nwu.edu (Andrew Bachmann) writes:

>(slot-value (class-prototype (find-class 'my-class))
>  'my-class-variable)

[ other CLOS adventures, clipped ]

>Well, you can do it like this:

>(defclass my-class ()
>  ()
>  (:documentation "Read Me"))

>Then the string is retrievable by using:

>(documentation (find-class 'my-class))

>(I know, I know, I could have just said that, but I thought the
>voyage into CLOS would be educational...)

I certainly appreciate the trip. While the :documentation would have
worked, it seems that it would be rather ... unsatisfying.

I think from what I've been playing so far is that one cannot play too
much with Lisp and CLOS, lest it suck you in...

Thanx alot (and to Tom, who also posted)!

-- 
Will Hartung - Rancho Santa Margarita. It's a dry heat. ······@netcom.com
1990 VFR750 - VFR=Very Red    "Ho, HaHa, Dodge, Parry, Spin, HA! THRUST!"
1993 Explorer - Cage? Hell, it's a prison.                    -D. Duck
From: Tim Bradshaw
Subject: Re: Class methods in CLOS?
Date: 
Message-ID: <ey3zpt6zob9.fsf@staffa.aiai.ed.ac.uk>
* Will Hartung wrote:

> (slot-value (make-instance 'my-class) 'my-class-variable)

> But, then I'm creating disposable objects for all the wrong reason,
> maybe.

There is MOP stuff -- I think CLASS-PROTOTYPE -- to do
this, but what I did/do is to store a table of dummy instances to use
for things like this and then define DUMMY-INSTANCE-OF which looks in
the table for an instance and returns it, or makes & stores a new one.
You need to be careful in the case where (MAKE-INSTANCE c) won't work
for some reason (for instance you may need to give it additional
arguments): I defined something like MAKE-DUMMY-INSTANCE which you
need to specialise using EQL methods (EQL to the class, since all the
metaclasses are the same), and a default method that just does
MAKE-INSTANCE. Also there can be (lesser) issues with redefinition.

(I found subclassing STANDARD-CLASS to be fraught with difficulty &
non-portability (I think there are bugs in the published MOP which
some people work around and some don't, but I forget the details).)

--tim