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


Hi, I'm having problems with pretty-printing, not with the
pretty-printing itself but getting something to pretty-print. The
problem seems to be with the dispatch table. BTW, I have Macintosh
Common Lisp Version 2.0p2.

The code below first makes a dummy package, then a dispatch table
based on the default one. Then I have a function that prints symbols
in the dummy package with the short nickname instead of the full
package name. At the bottom I install the pretty-printing function and
try both pretty-print and pprint-dispatch. None of these work. The
output is (the second two values are return values from

#<Compiled-function CCL::DEFUN-LIKE #x4C6E0E>

When I inspect *ppt-dispatch-table* I find references to the ppt::
symbols but it's hard to figure out what's wrong. Can someone please
enlighten me?

Hallvard Traetteberg

;;; the code

(defpackage "PRETTY-PRINT-TEST"
  (:nicknames :ppt)

(defvar *ppt-pprint-dispatch* (copy-pprint-dispatch nil))

(defun pprint-def-name (stream def-name)
  (flet ((package-prefix (symbol)
           (if (eq (symbol-package symbol) (find-package :ppt))
        (let ((package-prefix (package-prefix def-name)))
          (if package-prefix
            (format stream "~a::~a ~@_~:i" package-prefix def-name)
            (format stream "~w ~@_~:i"     def-name)))

(defun pprint-ppt-form (stream form)
  (pprint-logical-block (stream form :prefix "(" :suffix ")")
    (pprint-def-name stream (car form))
    (mapc #'pprint (cdr form))

(let ((*print-pprint-dispatch* *ppt-pprint-dispatch*))
  (set-pprint-dispatch '(cons (member ppt::define-ppt-1 ppt::define-ppt-2))

(let ((*print-pretty* t)
      (*print-pprint-dispatch* *ppt-pprint-dispatch*))
  (pprint '(ppt::define-ppt-1 ppt :key1 1 :key2 2))
  (pprint-dispatch '(ppt::define-ppt-1 ppt :key1 1 :key2 2)))
Hallvard Traetteberg
Dept. of Knowledge Based Systems
SINTEF SI (Center for Industrial Research)
Box 124 Blindern, 0314 Oslo 3

Tlf: +47 22 06 79 83 or  +47 22 06 73 00
Fax: +47 22 06 73 50
Email: Hallvard.Tretteberg@si.sintef.no