From: Lowell
Subject: why doesn't this work?
Date: 
Message-ID: <bhgref$gek$1@mughi.cs.ubc.ca>
(defmethod lt ((x base-char) (y base-char))
   (char< x y))

The error message I get says:
*** - FIND-CLASS: BASE-CHAR does not name a class
which seems to mean that base-char is not a type designator. But when I 
do (type-of #\A) it returns base-char, which seems to mean that 
base-char IS a type designator. What gives?

Lowell

From: Edi Weitz
Subject: Re: why doesn't this work?
Date: 
Message-ID: <87fzk4oszv.fsf@bird.agharta.de>
On Thu, 14 Aug 2003 13:29:04 -0700, Lowell <······@cs.ubc.ca> wrote:

> (defmethod lt ((x base-char) (y base-char))
>    (char< x y))
> 
> The error message I get says:
> *** - FIND-CLASS: BASE-CHAR does not name a class
> which seems to mean that base-char is not a type designator. But when
> I do (type-of #\A) it returns base-char, which seems to mean that
> base-char IS a type designator. What gives?

See 4.3.7 of the HyperSpec. DEFMETHOD dispatches on classes. While
every class has a corresponding type not every type must have a
corresponding class. Figure 4-8 lists classes that correspond to
pre-defined type specifiers. BASE-CHAR is not amongst them so your
implementation is allowed to do what it does.

It doesn't have to, though. Here's CMUCL's (18e) behaviour:

  * (defmethod lt ((x base-char) (y base-char))
      (char< x y))

  #<Standard-Method LT (BASE-CHAR BASE-CHAR) {4850AD8D}>
  * (lt #\a #\b)

  T
  * (lt #\b #\a)

  NIL

Edi.
From: Lowell
Subject: Re: why doesn't this work?
Date: 
Message-ID: <bhgtp2$h0m$1@mughi.cs.ubc.ca>
Good answer - Thanks :-)

Edi Weitz wrote:
> On Thu, 14 Aug 2003 13:29:04 -0700, Lowell <······@cs.ubc.ca> wrote:
> 
> 
>>(defmethod lt ((x base-char) (y base-char))
>>   (char< x y))
>>
>>The error message I get says:
>>*** - FIND-CLASS: BASE-CHAR does not name a class
>>which seems to mean that base-char is not a type designator. But when
>>I do (type-of #\A) it returns base-char, which seems to mean that
>>base-char IS a type designator. What gives?
> 
> 
> See 4.3.7 of the HyperSpec. DEFMETHOD dispatches on classes. While
> every class has a corresponding type not every type must have a
> corresponding class. Figure 4-8 lists classes that correspond to
> pre-defined type specifiers. BASE-CHAR is not amongst them so your
> implementation is allowed to do what it does.
> 
> It doesn't have to, though. Here's CMUCL's (18e) behaviour:
> 
>   * (defmethod lt ((x base-char) (y base-char))
>       (char< x y))
> 
>   #<Standard-Method LT (BASE-CHAR BASE-CHAR) {4850AD8D}>
>   * (lt #\a #\b)
> 
>   T
>   * (lt #\b #\a)
> 
>   NIL
> 
> Edi.
From: Frode Vatvedt Fjeld
Subject: Re: why doesn't this work?
Date: 
Message-ID: <2hadac54qt.fsf@vserver.cs.uit.no>
Lowell <······@cs.ubc.ca> writes:

> (defmethod lt ((x base-char) (y base-char))
>    (char< x y))
>
> The error message I get says:
> *** - FIND-CLASS: BASE-CHAR does not name a class
> which seems to mean that base-char is not a type designator. But when
> I do (type-of #\A) it returns base-char, which seems to mean that
> base-char IS a type designator. What gives?

That not all types are classes. What essentially happens when a
generic function is called is that the method is dispatched based on
the (class-of <arg>) for each argument. Read about types and classes
in the HyperSpec.

-- 
Frode Vatvedt Fjeld
From: Kaz Kylheku
Subject: Re: why doesn't this work?
Date: 
Message-ID: <cf333042.0308181012.3bd67f39@posting.google.com>
Frode Vatvedt Fjeld <······@cs.uit.no> wrote in message news:<··············@vserver.cs.uit.no>...
> Lowell <······@cs.ubc.ca> writes:
> > I do (type-of #\A) it returns base-char, which seems to mean that
> > base-char IS a type designator. What gives?
> 
> That not all types are classes.

In fact, *no* types are classes.  :)
From: Kaz Kylheku
Subject: Re: why doesn't this work?
Date: 
Message-ID: <cf333042.0308181011.4c7e2ed2@posting.google.com>
Lowell <······@cs.ubc.ca> wrote in message news:<············@mughi.cs.ubc.ca>...
> (defmethod lt ((x base-char) (y base-char))
>    (char< x y))
> 
> The error message I get says:
> *** - FIND-CLASS: BASE-CHAR does not name a class
> which seems to mean that base-char is not a type designator. But when I 

Type and class are separate concepts in Lisp. A value can have both a
type and class. This is both a historic artifact of an object system
being bolted on top of an existing language, and a useful distinction.

It's useful because it means that you can ignore the object system if
you want to, and work in a language in which there are no classes.
That language subset doesn't have to deal with the baggage of the
object system.

But when you do use the object system, then the simple types are
properly classified and can participate nicely in the object system.
You can dynamically dispatch on the distinction between a simple
string and integer, and so on.

The classification is not a simple one class for one type. For
example, in the type system, you have FIXNUM and BIGNUM integers. But
under the object system, you just have an INTEGER class; it's not
further refined into FIXNUM and BIGNUM classes, so you can't directly
write methods whose dispatch is specialized to this low level detail.

> do (type-of #\A) it returns base-char, which seems to mean that 
> base-char IS a type designator. What gives?

Try CLASS-OF to find out the class of something. CLASS-OF will give
you an actual object that represents a class (classes are objects in
Lisp). The CLASS-NAME accessor will then give you the symbol which
names the class, and which you use when writing methods, etc:

  (class-name (class-of #\a))

The printed representation of the (class-of #\a) return value itself
will likely also reveal the class name, something like
#<BUILT-IN-CLASS CHARACTER>.