From: Slava Akhmechet
Subject: Specializing on values of (class-of 'class-name)
Date: 
Message-ID: <87mywkt8sd.fsf@gmail.com>
I have a somewhat unusual situation where I need to specialize generic
functions on classes, not on their instances:

  (defmethod foo ((x (eql (find-class 'integer))))
    1)

I can now call FOO like this:

  (foo (find-class 'integer)) => 1

But unfortunately this will fail:

  (foo (find-class 'fixnum))

This makes sense because

  (eql (find-class 'fixnum) (find-class 'integer)) => NIL

however it seems like there must be some way to do this because

  (subtypep (find-class 'fixnum) (find-class 'integer)) => T

The only solution I can think of is use 'class-prototype' and pass
that instead of the return value of 'find-class', but is there another
way?

-- 
Regards,
Slava Akhmechet.
From: Pascal Costanza
Subject: Re: Specializing on values of (class-of 'class-name)
Date: 
Message-ID: <5j955mF3ta8f5U1@mid.individual.net>
Slava Akhmechet wrote:
> I have a somewhat unusual situation where I need to specialize generic
> functions on classes, not on their instances:
> 
>   (defmethod foo ((x (eql (find-class 'integer))))
>     1)
> 
> I can now call FOO like this:
> 
>   (foo (find-class 'integer)) => 1
> 
> But unfortunately this will fail:
> 
>   (foo (find-class 'fixnum))
> 
> This makes sense because
> 
>   (eql (find-class 'fixnum) (find-class 'integer)) => NIL
> 
> however it seems like there must be some way to do this because
> 
>   (subtypep (find-class 'fixnum) (find-class 'integer)) => T
> 
> The only solution I can think of is use 'class-prototype' and pass
> that instead of the return value of 'find-class', but is there another
> way?

You could try to define a new generic function class, introduce a new 
specializer class and redefine method dispatch for the new generic 
function class such that it recognizes the new specializers. This has 
been tried before (google for class-eq) but doesn't seem to be trivial.

...and Kenny won't like it. ;)


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/