#337 print-object built-in object: no-applicable-method

closed-fixed
Sam Steingold
clisp (525)
5
2006-07-27
2006-05-05
Jörg Höhle
No

CLHS says about PRINT-OBJECT: "Each implementation is
required to provide a method on the class standard-
object and on the class
structure-object. In addition, each implementation
must provide methods on enough other classes so as to
ensure that there is always an applicable method."

Contrary to this, print-object signals a NO-APPLICABLE-
METHOD:
(print-object 2 *standard-output*)
*** - NO-APPLICABLE-METHOD: When calling
#<STANDARD-GENERIC-FUNCTION PRINT-OBJECT>
with arguments (2 #<IO SYNONYM-STREAM *TERMINAL-
IO*>), no method is
applicable.

I came across this trying out the CLHS example about
pprint dispatch tables:
(set-pprint-dispatch '(cons (member my-let))
(pprint-dispatch '(let) nil))
With NO-APPLICABLE-METHOD, the following identity
mentioned abour PPRINT-DISPATCH does not hold:
(let ((*print-pretty* t))
(write object :stream s))
== (funcall (pprint-dispatch object) s object)
because pprint-dispatch defers to PRINT-OBJECT which
errors out.

Regards,
Jörg Höhle

Discussion

  • Sam Steingold
    Sam Steingold
    2006-07-27

    Logged In: YES
    user_id=5735

    instead of tediously writing a defmethod for each and every
    built-in class, I would rather have something like

    (defconstant print-object-methods-<instance-of-built-in-class>
    (list (defmethod print-object (obj (out stream)) (write
    obj :stream out))))
    (remove-method #'print-object
    (first
    print-object-methods-<instance-of-built-in-class>))
    (defmethod compute-applicable-methods-using-classes
    ((gf (eql #'print-object)) args)
    (multiple-value-bind (l p) (call-next-method)
    (if (and (null l)
    (eq (class-of (first args)) <built-in-class>)
    (eq (second args) <stream>))
    (values
    print-object-methods-<instance-of-built-in-class> t)
    (values l p))))

    alas, this causes a stack overflow in bootstrap
    and has no effect when type at the prompt.

     
  • Sam Steingold
    Sam Steingold
    2006-07-27

    • assigned_to: haible --> sds
    • status: open --> closed-fixed
     
  • Sam Steingold
    Sam Steingold
    2006-07-27

    Logged In: YES
    user_id=5735

    thank you for your bug report.
    the bug has been fixed in the CVS tree.
    you can either wait for the next release (recommended)
    or check out the current CVS tree (see http://clisp.cons.org\)
    and build CLISP from the sources (be advised that between
    releases the CVS tree is very unstable and may not even build
    on your platform).