From: David Cooper
Subject: Do CLOS methods only dispatch on CLOS object types and primitive types?
Date: 
Message-ID: <3659C77D.26E89777@genworks.com>
Hello Lispers,

I am trying to write some defmethods for dispatching
on ICAD/IDL objects (that's ICAD Design Language, not
Interface Definition Language). Nominally, IDL objects
have only single dispatching since they are (for the
moment) Flavors-based. 

Normal IDL methods are defined within the defpart 
object definition, and dispatch only on the type 
of self, the rest of the arguments are like normal 
function arguments.

I want to write some common-lisp:defmethods which
dispatch on an argument list which might contain 
some IDL objects. The IDL objects do indeed respond
to typep, so it seems that CLOS methods should be 
able to distinguish their type and dispatch on them:


>(defpart myobj (base-object))
BOX

>(setq self (make-part 'myobj))
#<MYBOX 23334>

>(typep self 'myobj)
T

>(typep self 'base-object)
T

>(the-object self :strings-for-display)
"Myobj"

>(common-lisp:defmethod compare-lessp 
    ((string1 string) (string2 string))
   (string-lessp string1 string2))
#<COMMON-LISP:STANDARD-METHOD COMPARE-LESSP (STRING STRING)>

>(common-lisp:defmethod compare-lessp
    ((num1 number) (num2 number))
  (> num1 num2))
#<COMMON-LISP:STANDARD-METHOD COMPARE-LESSP (NUMBER NUMBER)>

>(common-lisp:defmethod compare-lessp
    ((obj1 base-object) (obj2 base-object))
  (string-lessp (the-object obj1 :strings-for-display)
                (the-object obj2 :strings-for-display)))
Error: No class named: BASE-OBJECT


  :(


The ugly alternative compromise I am using at the moment looks
something like:

>(common-lisp:defmethod compare-lessp
   ((obj1 t) (obj2 t))
  (etypecase obj1
   (base-object
     (etypecase obj2
       (base-object
         (string-lessp 
          (the-object obj1 :strings-for-display)
          (the-object obj2 :strings-for-display)))))))


or something similarly ugly and brittle.


 -djc

From: Barry Margolin
Subject: Re: Do CLOS methods only dispatch on CLOS object types and primitive types?
Date: 
Message-ID: <Psu62.35$OP3.4696@burlma1-snr1.gtei.net>
In article <·················@genworks.com>,
David Cooper  <········@genworks.com> wrote:
>I want to write some common-lisp:defmethods which
>dispatch on an argument list which might contain 
>some IDL objects. The IDL objects do indeed respond
>to typep, so it seems that CLOS methods should be 
>able to distinguish their type and dispatch on them:

CLOS dispatches on classe, not types.  What does CLASS-OF return for these
objects?

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.
From: David Cooper
Subject: Re: Do CLOS methods only dispatch on CLOS object types and primitive types?
Date: 
Message-ID: <365ADA80.DFE5E67@genworks.com>
Barry Margolin wrote:
> 
> 
> CLOS dispatches on classes, not types.  What does CLASS-OF return for these
> objects?
> 

#<COMMON-LISP:BUILT-IN-CLASS EXCL::INSTANCE>
From: Kelly Murray
Subject: Re: Do CLOS methods only dispatch on CLOS object types and primitive types?
Date: 
Message-ID: <365B0D46.27E02CAB@IntelliMarket.Com>
David Cooper wrote:
> 
> Barry Margolin wrote:
> >
> >
> > CLOS dispatches on classes, not types.  What does CLASS-OF return for these
> > objects?
> >
> 
> #<COMMON-LISP:BUILT-IN-CLASS EXCL::INSTANCE>

This is a Flavor instance, not CLOS