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

Re: Re: Customizing hash table printing?



On 29 Aug 2000, Hannu Koivisto wrote:
> 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?

The problem is that for things like list and vector their is a special
print routine called and it doesn't use the default print handling for the
elements.  You could check list in your handler and loop through the
elements calling the default handler which would then call yours.

-- 
Spruce: boldly goes where no client has gone before!