PRINT-OBJECT for built-in classes

Edi Weitz edi at weitz.de
Sat Aug 29 09:10:15 UTC 2015


The following "works" in three different CL implementations I tried
while in three others the way complex numbers are printed doesn't
change.

? (defmethod print-object ((obj complex) stream)
     (format stream "#< ~A + ~A * I >"
                (realpart obj) (imagpart obj)))
#<STANDARD-METHOD PRINT-OBJECT (COMPLEX T)>
? #c(1 1)
#< 1 + 1 * I >

My understanding of 22.1.2 of the standard is that each Lisp MUST have
a PRINT-OBJECT method for complex numbers.  The question then is
whether I'm allowed to redefine it like above (I think I am) and/or
whether an implementation is allowed to accept this redefinition
without a warning but then to ignore it (which, as I said, is what
happens in three respectable Lisps).

Thanks,
Edi.

[Note: There's no point in talking me out of this as I don't actually
want to do it anyway.  It's just an example and I'm only interested in
what exactly is governed by the standard.  Complex numbers are also
just an example.  I'm interested in PRINT-OBJECT for built-in classes
in general.]



More information about the pro mailing list