[Openmcl-devel] describe

Gary Byers gb at clozure.com
Thu Jul 3 20:58:11 PDT 2003

On Thu, 3 Jul 2003, Paul wrote:

> Hash: SHA1
> Is describe supposed to be a generic function? I was working through
> some examples in my CLOS book and ran into trouble - I tried to
> specialize describe and quickly discovered that in openmcl it is *not*
> a generic function. I was curious if this is a departure from the spec,
> or an implementation decision.
> Thanks
> Paul D. Lathrop

DESCRIBE is a non-generic function; it takes one required argument
(the thing to be described) and an optional argument used to designate
an output stream.  DESCRIBE basically maps any "stream designators" (T
or NIL) in its STREAM argument to a real stream, calls DESCRIBE-OBJECT,
and returns 0 values.

DESCRIBE-OBJECT is a generic function; one typically defines methods
that specialize on DESCRIBE-OBJECT's first argument, in order to
influence DESCRIBE's behavior.

For instance:

(defclass rgb-color ()
  ((red :initarg :red :accessor rgb-color-red)
   (green :initarg :green :accessor rgb-color-green)
   (blue :initarg :blue :accessor rgb-color-blue)))

(defmethod describe-object ((r rgb-color) stream)
  (format stream "~&~s is a ~s.  Its red component is ~s, its green component is ~s, and its blue component is ~s"
   r (class-name (class-of r)) (rgb-color-red r) (rgb-color-green r) (rgb-color-blue r)))

This is how things are defined in the spec and in OpenMCL; your CLOS book
is mistaken (or, more likely, outdated) if it suggests otherwise.  In
1988, the X3J13 committee (the committee responsible for developing the
ANSI CL standard) incorporated CLOS into the language and the original
CLOS definition (re-)defined DESCRIBE as a generic function.  The CLOS
definition of DESCRIBE had some shortcomings which X3J13 attempted to
rectify by introducing the generic function DESCRIBE-OBJECT and making
DESCRIBE be non-generic again (and adding an optional STREAM argument
to DESCRIBE).  This happened in early 1989; if the book you're using
was published in that time frame, it may have missed that change to the
language.  (Sonya Keene's CLOS book was published in 1989 and is generally
very good.)

Openmcl-devel mailing list
Openmcl-devel at clozure.com

More information about the Openmcl-devel mailing list