Subject: Re: pretty printer

From: haible (Bruno Haible)
Date: Thu, 27 Jan 94 16:43:06 +0100

Joachim Schrod <[email-masked]> says:

> CLtL2, Chapter 27, describes a prettyprinting facility.

CLtL2, Chapter 27, describes the XP "pretty" printer.

> How about XP, is it available by anonymous ftp?
> Or is one in CMUCL that might be used?

XP is used in CMU CL and WCL.

> It may not be plug&play, we're not afraid of some programming work.

But decide first what you want. I will try a comparison between CLISP's
pretty printer and XP as specified in CLtL2 and implemented in xp.lisp.

PRO XP:
  XP is extensible. A programmer/user can specify how his DO, LET,
  MULTIPLE-VALUE-BIND etc. forms are printed.
CONTRA XP:
  If a pretty-print layout becomes mandatory for every macro, then writing
  macros becomes combersome.
CONTRA XP:
  It looks ugly when a list containing data which happens to look like
  (LET ...) is printed as if it were a Lisp form. There is no way by which
  the system could decide whether some object is data or program.

CONTRA CLISP:
  CLISP indents by 1 for every nesting level. XP indents by 2, which makes
  up for better readability. (This could be easily fixed in io.d.)
PRO CLISP:
  Closing parentheses are output just below their corresponding opening
  parenthesis, if *PRINT-RPARS* is T. This makes it much easier for a human
  reader to find out where a certain nesting level ends.

CONTRA XP, PRO CLISP:
  Heavily nested lists and structures tend to reach the right margin very
  quickly in XP. This fact is even recognized by the existence of the variable
  *PRINT-MISER-WIDTH*. And it is not handled satisfactorily in XP: it
  produces lots of lines with much space on the left and only one token
  at the right margin, often exceeding the line length.

PRO CLISP:
  While the *PRINT-CIRCLE* mechanism used in XP uses a large hash table
  which holds every subobject of the object to be printed, CLISP's
  *PRINT-CIRCLE* handling builds up a (usually much smaller) hash table
  which holds only those subobjects which occur more than once.
  (Detection of these subobjects is done by a low-level subroutine.)
PRO XP:
  When *PRINT-LENGTH* or *PRINT-LEVEL* is non-NIL, CLISP may print  #n=
  with no #n# references:  #1=(A ...)
  XP does this better because its decision whether to print  #n=  comes
  last.

                    Bruno Haible
                    [email-masked]

---

From: Joachim Schrod <[email-masked]>
Date: Thu, 27 Jan 1994 17:27:46 +0100 (MEZ)

> CLtL2, Chapter 27, describes the XP "pretty" printer.

First, thanks to the anon ftp site pointer. (I should have checked the
Lisp FAQ by myself. :( )

> pretty printer and XP as specified in CLtL2 and implemented in xp.lisp.

I need a prettyprinting facility that is programmable. Actually, I
need them for output of datastructures, not for Lisp programs. In
particular, that has the consequence that I must be able to influence
the current indentation.

Facilities like the `logical block' concept, the specification of
indentation and conditional breakpoints, and the pprint dispatcher
are helpful in this problem context. That was the reason I started to
look for extensible prettyprinters.

Since chapter 27, (ie XP, as I learned in the meantime), is simply a
Lisp realization of the abstraction beneath the classic
prettyprinting papers (Oppen [TOPLAS 2(4)], Rose/Welsh [SP&E
11(11)]), and since these abstractions were quite useful in other
projects I did, I thought I might use them. Did anybody have bad
experiences in using XP for output of data structures? (The
application at hand is the output of nested objects, where a
top-level object will cover approx. 40 lines.)

	Joachim

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Joachim Schrod			Email: [email-masked]
Computer Science Department
Technical University of Darmstadt, Germany