Printing a custom representation of hash table at the repl

Stas Boukarev stassats at gmail.com
Thu Jul 7 11:12:19 UTC 2016


According to http://www.lispworks.com/documentation/HyperSpec/Body/11_abab.htm
section 19,
you can't actually define such methods.

On Thu, Jul 7, 2016 at 1:13 PM, Diogo Franco <diogoalexfranco at gmail.com> wrote:
> Hello,
>
> ecl does not specialize the print-object method on hash-tables:
>
>> > (find-method #'print-object '() '(hash-table t))
>> Debugger received error of type: SIMPLE-ERROR
>> There is no method on the generic function PRINT-OBJECT that agrees on
>> qualifiers NIL and specializers (HASH-TABLE T)
>
>
> After reading the hyperspec carefully, I think this is ok, it only requires
> it on standard-object and structure-object. However, i still thought that
> specializing on hash-table would work, but it doesn't:
>
>> >> (defmethod print-object ((obj hash-table) stream) (princ "its working"
>> >> stream))
>> #<standard-method PRINT-OBJECT (#<The BUILT-IN-CLASS HASH-TABLE> #<The
>> BUILT-IN-CLASS T>)>
>> >> (make-hash-table)
>> #<hash-table 000000000493ee40>
>
>
> Shouldn't we still dispatch the call to this method? And if not, what's the
> best way in ecl to customize the printable representation of a hash-table?
>
> I've tried:
>>
>> > (set-pprint-dispatch 'hash-table (lambda (s obj) (princ "its working"
>> > s)))
>> NIL
>> > (make-hash-table)
>> its working
>
>
> But this sometimes gives an error:
>>
>> Debugger received error of type: SIMPLE-ERROR
>> Tried to modified a read-only pprint dispatch table:
>> #<pprint-dispatch-table  0000000003375210>
>> Error flushed.
>
>
> Thanks!



-- 
With best regards, Stas.



More information about the ecl-devel mailing list