From: R. Matthew Emerson
Subject: *print-readably* and structures
Date: 
Message-ID: <87iu7fhros.fsf@nightfly.apk.net>
Consider the following structure:

(defstruct (point
            (:constructor make-point (x y z &optional (w 1.0))))
  (x 0.0)
  (y 0.0)
  (z 0.0)
  (w 0.0))

Is it reasonable to expect the printer to signal an error
when printing an instance of this structure when *print-readably* is t?
Objects like #s(point :x 0 :y 0 :z 0 :w 1) can't be read with
the above structure definition.

The HyperSpec enabled me to figure out how to use the #s syntax
and still have the boa constructor, too.  Neither Graham's ANSI
Common Lisp nor CLTL2 (which is out of date, especially on this
topic) say how to do this. Yay for the HyperSpec!

(defstruct (point
            (:constructor new-point (x y z &optional (w 1.0)))
	    (:constructor))
  (x 0.0)
  (y 0.0)
  (z 0.0)
  (w 0.0))

-matt

From: Kent M Pitman
Subject: Re: *print-readably* and structures
Date: 
Message-ID: <sfwk8ru4wjy.fsf@world.std.com>
···@nightfly.apk.net (R. Matthew Emerson) writes:

> Is it reasonable to expect the printer to signal an error
> when printing an instance of this structure when *print-readably* is t?
> Objects like #s(point :x 0 :y 0 :z 0 :w 1) can't be read with
> the above structure definition.

No.  I think you should assume that you shouldn't be printing anything 
and expecting it to be re-readable unless the same definitions are
loaded.  For example, you are obliged to have the same package structure
and you won't get an error if you try to print a package that might not
be loaded at re-read time.  The burden is on you to make sure a compatible
environment is in place for the re-read.  *print-readably* is only supposed
to address the issue of whether that same compatible environment contained
no way to invert the output rep.

I'm not sure it says this anywhere in the spec.  But rationality kind of
implies it and I bet (without checking) you'll find all implementations
make the assumption I just said.  I would be very surprised if any
implementation signaled an error in the case you describe, and if it did
I would send a bug report.
From: Pekka P. Pirinen
Subject: Re: *print-readably* and structures
Date: 
Message-ID: <ixiu7d24hb.fsf@gaspode.cam.harlequin.co.uk>
Kent M Pitman <······@world.std.com> writes:
> ···@nightfly.apk.net (R. Matthew Emerson) writes:
> 
> > Is it reasonable to expect the printer to signal an error
> > when printing an instance of this structure when *print-readably* is t?
> > Objects like #s(point :x 0 :y 0 :z 0 :w 1) can't be read with
> > the above structure definition.
> 
> No.  I think you should assume that you shouldn't be printing anything 
> and expecting it to be re-readable unless the same definitions are
> loaded.

Kent, I think you misread him: he said "with", not "without".  The
reason #S(point ...) can't read with that structure definition is that
it didn't include a standard constructor function, as required by ANS
2.4.8.13:

> > (defstruct (point
> >             (:constructor make-point (x y z &optional (w 1.0))))
> >   (x 0.0)
> >   (y 0.0)
> >   (z 0.0)
> >   (w 0.0))

I'd be inclined to say the printer should signal an error: Stricly
speaking, that structure can't be printed readably, since the
definition of "readably" involves similarity, and similarity is not
defined on a structure type (ANS 3.2.4.2.2), unless you define a
MAKE-LOAD-FORM method for it.  Even if "readably" was extended with a
special case for #S, it would not be too much to ask for the printer
to check that the required constructor exists.

Now, if there was a MAKE-LOAD-FORM method, the printer could call it
and construct a readable representation using #. on the results (the
details are a little complicated).  There's plenty of precedent for
*PRINT-READABLY* changing the behaviour of the printer.

However, it is not reasonable to expect the printer in the current
implementations to signal an error.  I doubt many implementors have
worked out the somewhat counterintuitive implications of these
definitions.
-- 
Pekka P. Pirinen
(the new) Harlequin Limited
All that glitters has a high refractive index.
From: Kent M Pitman
Subject: Re: *print-readably* and structures
Date: 
Message-ID: <sfwemi1d78z.fsf@world.std.com>
·····@harlequin.co.uk (Pekka P. Pirinen) writes:

> Kent, I think you misread him: he said "with", not "without".

So I did.

> I'd be inclined to say the printer should signal an error:

Yeah, it does seem in this case that it's not an unreasonable 
thing to do.  I don't think it's required, only because of how the
spec is worded.  But nothing keeps a vendor from "helping".
I'd have to think a lot to be absolutely sure, but it *sounds* helpful.
 
> Now, if there was a MAKE-LOAD-FORM method, the printer could call it
> and construct a readable representation using #. on the results

Yeah, I do that sometimes...