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

Re: Customizing hash table printing?



Robert John Andersen <robert_andersen@bridge-point.com> writes:

| You can replace the current print proc with one of your own.  See sections
| Port in Built-in parameters and Customizing Display, Write, and Print in
| Ports.  Don't forget to save the current print proc and call that if what
| is supposed to get printed isn't what your looking to change.

I saw those sections and even tried that approach but because I
couldn't get it to work and as the documentation suggests by not
telling any other protocol, I assumed that one needs to replace the
whole printer at once and cannot call the original one trusting
that it will call my version to recursively print, for example,
list elements.  As an example:

(let ((hieno (global-port-print-handler)))
  (parameterize ((global-port-print-handler
                  (lambda (x port)
                    (when (hash-table? x) (hieno "hash!" port))
                    (hieno x port))))
    (print (list 1 2 3 (make-hash-table)))))
=> (1 2 3 #<hash-table>)

(let ((hieno (global-port-print-handler)))
  (parameterize ((global-port-print-handler
                  (lambda (x port)
                    (when (hash-table? x) (hieno "hash!" port))
                    (hieno x port))))
    (print (make-hash-table))))
=> "hash!"#<hash-table>

So my version is not called in the first case to print the hash
table in the list.  Or am I just missing something obvious?

-- 
Hannu