Diogo Franco diogoalexfranco@gmail.com writes:
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?
You should not.
The implementation is free to define methods for print-object on standard classes, but you must not do so.
This is because the methods the implementation uses to print standard classes could be broken by your method!
You can define methods for print-object, only on the classes you define yourself.
Instead, you can define another printing function:
(defgeneric print-lisp-object (object stream) (:method ((object t) stream) (print-object object stream)))
define methods on print-lisp-object, and then use PRINT-LISP-OBJECT instead of PRINT.