PRINT-OBJECT for built-in classes

Pascal Costanza pc at p-cos.net
Sat Aug 29 11:23:16 UTC 2015


The consequences are undefined if you do this. See http://www.lispworks.com/documentation/HyperSpec/Body/11_abab.htm item 19.

Pascal

> On 29 Aug 2015, at 11:10, Edi Weitz <edi at weitz.de> wrote:
> 
> 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.]
> 

--
Pascal Costanza
The views expressed in this email are my own, and not those of my employer.






More information about the pro mailing list