From: SourceForge.net <no...@so...> - 2012-02-14 12:53:00
|
Bugs item #3487523, was opened at 2012-02-14 02:27 Message generated for change (Comment added) made by haible You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101355&aid=3487523&group_id=1355 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: clisp >Group: lisp error >Status: Closed >Resolution: Invalid Priority: 5 Private: No Submitted By: Vladimir Tzankov (vtz) Assigned to: Bruno Haible (haible) Summary: print-unreadable-object recursion Initial Comment: Following code causes infinite recursion: (defclass c1 () ((name :initarg :name :accessor name-of))) (defmethod print-object ((c c1) stream) (print-unreadable-object (c stream :type t :identity t) (princ (name-of c) stream))) (make-instance 'c1) The message: *** - SLOT-VALUE: The slot NAME of XXXXXX has no value where XXXXXX is the newly created instance is to blame ---------------------------------------------------------------------- >Comment By: Bruno Haible (haible) Date: 2012-02-14 04:53 Message: This is not a bug. When writing a PRINT-OBJECT method you have to be more careful and more defensive than elsewhere, precisely because PRINT-OBJECT can be used in error messages. Change your method like this: (defmethod print-object ((c c1) stream) (print-unreadable-object (c stream :type t :identity t) (when (slot-boundp c 'name) (princ (name-of c) stream)))) ---------------------------------------------------------------------- Comment By: Pascal J. Bourguignon (informatimago) Date: 2012-02-14 04:42 Message: This is not a bug. If you don't bind a slot, it's normal to get an error when you try to access it. Either don't try to read unbound slot, or bind all your slots (with :initform). [pjb@kuiper :0 ~]$ clisp -ansi -norc -q [1]> (defclass c1 () ((name :initarg :name :accessor name-of))) #<STANDARD-CLASS C1> [2]> (defmethod print-object ((c c1) stream) (print-unreadable-object (c stream :type t :identity t) (princ (name-of c) stream))) #<STANDARD-METHOD (#<STANDARD-CLASS C1> #<BUILT-IN-CLASS T>)> [3]> (make-instance 'c1 :name "Hello") #<C1 Hello #x000333D0E7A0> [4]> (defmethod print-object ((c c1) stream) (print-unreadable-object (c stream :type t :identity t) (when (slot-boundp c 'name) (princ (name-of c) stream)))) WARNING: Replacing method #<STANDARD-METHOD (#<STANDARD-CLASS C1> #<BUILT-IN-CLASS T>)> in #<STANDARD-GENERIC-FUNCTION PRINT-OBJECT> #<STANDARD-METHOD (#<STANDARD-CLASS C1> #<BUILT-IN-CLASS T>)> [5]> (make-instance 'c1) #<C1 #x000333D29580> [6]> (quit) [pjb@kuiper :0 ~]$ ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101355&aid=3487523&group_id=1355 |