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!
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@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!
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.