#339 automatic pretty-printing of symbols in conses

clisp (525)

[Report by Tobias C. Rittweiler [tcr@freebits.de]:]
According to the CLHS, if no suitable entry for some
object is found in the current PPRINT-DISPATCH table
(assuming pretty-printing enabled), the internal
printer (i.e. some PRINT-OBJECT method) is supposed to
be invoked in an environment where *PRINT-PRETTY* is
_still_ bound to T. (See last paragraph in

Joerg Hoehle pointed out that Clisp seems to implement
CLtL2 behaviour which means that "if there is no
specification for how to pretty print a particular
kind of object, it is then printed using the standard
mechanisms as if *print-pretty* were nil." ([2])

Rationale why this change from NIL to T happened
between CLtL2 and standardization, can be found within
the UNIFY issue. [3]

This change comes apparent when one's trying to pretty-
print an aggregated data type, as for instance a LIST:

(flet ((my-symbol-pprint (stream obj)
(let ((*print-pretty* nil))
(princ "++" stream) (princ obj stream)
(princ "++" stream))))
(let ((*print-pprint-dispatch* (copy-pprint-
(set-pprint-dispatch 'symbol #'my-symbol-pprint)
(princ-to-string (macroexpand '(loop for i
in '(1 2 3) collect i)))))

This should prepend and append a "++" to every symbol
within the macroexpansion, because -- while the value
returned from MACROEXPAND isn't actually of type
SYMBOL (that a pprint-dispatch entry was added for) --
the respective PRINT-OBJECT method should be invoked
with *PRINT-PRETTY* bound to T. As a result and as a
consequence of the default list printing algorithm (as
outlined in [4]), the function #'MY-SYMBOL-
PPRINT should be invoked for every symbol _within_ the
list returned as macroexpansion.

That this behaviour is desired by the standard, can
also be seen in one of the examples of the
section "22.2.2 Examples of using the Pretty Printer"
[5] in the hyperspec:

(setq *print-pprint-dispatch* (copy-pprint-dispatch
(set-pprint-dispatch 'ratio
#'(lambda (s obj)
(format s "#.(/ ~W ~W)"
(numerator obj) (denominator obj))))
(pprint '(1/3 -2/3)) ==> (#.(/ 1 3) #.(- (/ 2 3)))

There has been a short discussion about the subject on
the clisp.general mailinglist. [6]

[1] http://www.lisp.org/HyperSpec/Body/sec_22-2-1-
[2] http://www.supelec.fr/docs/cltl/clm/node259.html
[3] http://www.lisp.org/HyperSpec/Issues/iss180-
[4] http://www.lisp.org/HyperSpec/Body/sec_22-1-3-
[5] http://www.lisp.org/HyperSpec/Body/sec_22-2-2.html


  • Sam Steingold

    Sam Steingold - 2006-11-17

    Logged In: YES
    Originator: NO

    thank you for your bug report.
    the bug has been fixed in the CVS tree.
    you can either wait for the next release (recommended)
    or check out the current CVS tree (see http://clisp.cons.org\)
    and build CLISP from the sources (be advised that between
    releases the CVS tree is very unstable and may not even build
    on your platform).

  • Sam Steingold

    Sam Steingold - 2006-11-17
    • assigned_to: haible --> sds
    • status: open --> closed-fixed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks