[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)

    I have an application that was written under Release 7.2 using Xerox's
    Public domain CLOS (PCL - May Day version).  It's a Telemetry processing
    system that uses thousands of CLOS objects of Class MEASUREMENT in our
    package SPORT - (Smart Processing of Real Time Telemetry).  The system 
    attempts to process and display them graphically.  To aid in debugging, 
    we wanted to change the default PRINT-OBJECT method to print additional
    name information utilizing a NAME slot in the object.  In PCL we were 
    defining the method as follows: 

    #+PCL
    CLOS:(defmethod print-object ((m sport::measurement) stream &rest ignore)
      (format stream "#<~A-~A>"
	      (class-name (class-of m))
	      (sport::m-name m)))

I don't understand entirely why this works.  The correct argument list for
PRINT-OBJECT is (OBJECT STREAM); no &REST argument should work.  I assume
CLOS is a nickname for the PCL package in your environment.  The PCL package
is defined using :COLON-MODE :INTERNAL, which means that PCL:M will intern
the symbol M in the package PCL even if it's not declared to be an external
symbol.

    When we attempted to port the code to Release 8.0, this method fails to
    compile.  I've tried different variations but nothing seems to work. 

    ;;; 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)))

In the above, you would need to say CLOS::(...), so it would act as if you
typed CLOS::M at the critical place in the source.  [This is not standard
Common Lisp, so don't expect this to work portably.]

    ;;; 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)))

As you can probably figure out by now, the right thing is something like
this:

  (CLOS:defmethod CLOS:print-object ((m measurement) stream)
    (format stream "#<~A-~A>"
	    (CLOS:class-name (CLOS:class-of m))
	    (m-name m)))

However, it might be better to USE the CLOS (or PCL) package from the SPORT
package, so you can just type

  (defmethod print-object ((m measurement) stream)
    (format stream "#<~A-~A>"
	    (class-name (class-of m))
	    (m-name m)))

[Your package declaration might look something like this:

 (defpackage SPORT
   (:use #+PCL PCL #-PCL CLOS
	 LISP)
   (:nicknames ...)
   (:export ...)
   (:import ...))

so it would work regardless of whether PCL is loaded or not.]