From: Tobias C. Rittweiler <tcr@fr...> - 2006-04-21 20:35:14
I'd expect something like the following
(flet ((my-symbol-pprint (stream obj)
(let ((*print-pretty* nil))
(princ "++" stream) (princ obj stream) (princ "++" stream))))
(let ((*print-pprint-dispatch* (copy-pprint-dispatch)))
(set-pprint-dispatch 'symbol #'my-symbol-pprint)
(princ-to-string (macroexpand '(loop for i in '(1 2 3) collect i)))))
to print out every symbol with leading and trailing ++. Granted, the
entry in the pprint-dispatch table is only for type SYMBOL and not for
(CONS SYMBOL), so maybe my expectations are simply wrong. On the other
hand, (FWIW anyway), other implementations I tried (SBCL, CMUCL, ACL)
behave the way I expect. Unfortunately, I find the CLHS to be somewhat
scarce on the whole pretty printer subject, so it's hard to find a
decisive answer; the closest argument for my case, is rather shallow, as
in 22.214.171.124 it says:
Therefore the following algorithm is used to print a cons x:
1. A left-parenthesis is printed.
2. The car of x is printed.
3. If the cdr of x is itself a cons, [...]
5. A right-parenthesis is printed.
Now, that's actually the algorithm for the case that *PRINT-PRETTY* is
NIL, but no such explicit algorithm is offered for the case where it's
T, since it's supposed to be similiar enough except for some mentioned
details. Now of course, the interesting point is what is meant with the
second point, "[t]he car of x is printed": Does this mean -- when
*PRINT-PRETTY* is true -- that the CAR of X is supposed to go through
the whole pretty printing mechanism? If so, I think my expectation is
What's your opinion?