[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Issue: PRINT-PRETTY-HOOK (version 1)



This is a bit late for a minor change.  But it looks like the
following will make my, and many others, lives much easier in the
future. 

---------------
Issue:         PRINT-PRETTY-HOOK
References:    *PRINT-PRETTY* p. 371, WRITE, PRINT, PPRINT, etc. pp. 382-383,
               FORMAT pp. 385-407
Category:      CHANGE, ADDITION
Edit history:  Version 1 by Pierson, 9/21/88
Status:        For Internal Discussion

Problem description:

Pretty printers are a part of the Common Lisp development environment
that are relatively easy for users to write themselves.  Furthermore,
vendor supplied pretty printers vary widely in quality.
Unfortunately, while it is easy for a user to write a pretty printer,
many other Common Lisp functions are defined to invoke the pretty
printer internally under control of the variable, *PRINT-PRETTY*.

Proposal (PRINT-PRETTY-HOOK:USE-VALUE):

Specify that if the value of *PRINT-PRETTY* is of type FUNCTION that
the function will be called with the standard arguments of PPRINT
whenever the pretty printer is to be invoked.

Test Cases/Examples:

(SETQ *PRINT-PRETTY* NIL) (PRINT FOO)
Will print the value of FOO without extra white space.

(SETQ *PRINT-PRETTY* T) (PRINT FOO)
Will print the value of FOO using the standard pretty printer.

(DEFUN MY-PPRINT (OBJECT &OPTIONAL OUTPUT-STREAM) ...)
(SETQ *PRINT-PRETTY* #'MY-PPRINT) (PRINT FOO)
(SETQ *PRINT-PRETTY* 'MY-PPRINT) (PRINT FOO)
Will both print the value of FOO using a special pretty printer.

Rationale:

This seems like the simplest portable method of allowing a user to
install a custom pretty printer.

Current practice:

I know of no Common Lisp implementation that supports this feature
(though it's not specifically forbidden by CLtL).

Cost to Implementors:

An additional funcall will have to be added everywhere the value of
*PRINT-PRETTY* is checked.  This should be fairly localized in most
implementations.

Cost to Users:

None, this is an upward-compatible change.

Cost of non-Adoption:

Users will continue to be stuck with the vendor-supplied pretty
printer in many cases.

Benefits:

Users will be able to modify this part of the programming environment
to suite their tastes.  In addition, users of extendable pretty
printers will be able to ensure that their extensions are portably
available in all Common Lisp environments.

Aesthetics:

This sort of hook could well be considered an additional wart on the
language. 

Discussion:

This proposal was inspired by Dick Water's announcement of a
forthcoming portable Common Lisp pretty printer.

Like editors, pretty printers tend to be very much a matter of taste.
Since the language defines several ways that the pretty printer gets
invoked, the user should have control over which pretty printer is
used across as many of these ways as possible.