[plt-dev] Re: [plt-bug] all/10895: quasiquote printing is buggy, confusing

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon May 10 20:51:31 EDT 2010

At Mon, 10 May 2010 14:29:49 -0400, Carl Eastlund wrote:
> On Mon, May 10, 2010 at 2:02 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> >>
> >> This suggests that no one is writing custom printers that should be
> >> quoted.  Further, since there's no mechanism for structs to
> >> automatically extend the read syntax and the behavior of `quote', only
> >> very rarely will structs be usefully printed in a quoted form.  Both
> >> of these pieces of evidence suggest to me that quoting is the wrong
> >> default.
> >
> > I think the piece/default that's missing is an "unreadable" property.
> > There's currently no way to say that a custom-write procedure produces
> > unreadable output, even though the printer otherwise treats unreadable
> > values specially: It doesn't put a quote in front, although it lets a
> > unreadable value be quoted if it appears within otherwise quotable
> > value).
> >
> > So, how about replacing `prop:custom-print-as-expression' with
> > `prop:custom-print-mode' whose value is either 'unreadable,
> > 'unquotable, or 'quotable, where the default is effectively
> > 'unreadable?
> I think the default should be unquotable, because it is the only mode
> that sensibly allows a custom printer to recursively print contained
> values (that might themselves be unquotable).

FWIW, I had in mind "maybe quotable" for 'quotable mode, where the
value is quotable only if its content is quotable. That turned into
the 'maybe property...

The new property is actually called `prop:custom-print-quotable' with
four possible values:

 * 'self (the default) --- mostly suitable for unreadable values, with
   are "self quoting" in the sense that they print the same in either
   quoted or unquoted positions.

   Conceptually, at least, a procedure has this property value, since
   it prints as #<procedure> in either quoted or unquoted positions.

 * 'never (like setting 'prop:custom-print-as-expression' to #t) ---
   for a structure type that always wants to print as an expression.

   A transparent, non-prefab structure type without a custom printer
   behaves as if it has the 'never property.

 * 'maybe --- quotable if all of the structure's content is quotable;
   the content is determined by recursive printing calls from the
   `prop:custom-write' procedure.

   A pairs, vectors, and prefab structures all behave as if they have
   the 'maybe property.

 * 'always --- always quotable.

   An empty list behaves as if it has the 'always property, though you
   could also consider it as having the 'maybe property with all 0 of
   its parts being quotable.

Posted on the dev mailing list.