[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How do you override CLOS:PRINT-OBJECT?



    Date: Fri, 15 Jun 1990 18:37:17 EDT
    From: DUMOULIN@TITAN.KSC.NASA.GOV (Jim Dumoulin)

    ;;; Gets you Error - Attempt to access not existent symbol CLOS:M
    CLOS:(defmethod print-object ((m sport::measurement) stream &rest ignore)
      (format stream "#<~A-~A>"
	      (class-name (class-of m))
	      (sport::m-name m)))

By putting the CLOS: outside the list you are trying to read the symbol
CLOS:M, which doesn't exist.

    ;;; Gets you Error - Lambda lists arn't congruent
    (CLOS:defmethod CLOS:print-object ((m SPORT::measurement) stream &rest ignore)
      (format stream "#<~A-~A>"
	      (CLOS:class-name (CLOS:class-of m))
	      (sport::m-name m)))

"Show CLOS Generic Function PRINT-OBJECT" says that the arguments are
(OBJECT STREAM).  The descriptions on p.850 of CLtL2 and 244 of Keene's
book both agree with this.  The argument list of all methods for a
generic function must agree with the argument list for the generic
function; you aren't permitted to add additional &optional, &rest, or
&key parameters (well, actually there is some weirdness with &key, but
that's beside the point).

PCL isn't exactly CLOS, so it may not have the same method signature for
PRINT-OBJECT or it may not do all the congruency checking that's
required.

So, remove the "&rest ignore" from the above version and you should be
OK.

    ;;; compiles but isn't called when the object attempts to print itself
    (CLOS:defmethod print-object ((m SPORT::measurement) stream &rest ignore)
      (format stream "#<~A-~A>"
	      (CLOS:class-name (CLOS:class-of m))
	      (sport::m-name m)))

All CLOS-specific functions are in the CLOS package, so the function to
specialize is CLOS:PRINT-OBJECT.

                                                barmar