From: Richard M K. <kr...@pr...> - 2007-05-09 15:46:15
|
Yaroslav Kavenchuk <kav...@tu...> writes: > If I define condition with slot but wothout :reader specification - I > take STYLE-WARNING. > > Example: > > $ cat test-error.lisp > (define-condition my-error (error) > ((field1 :initarg :field1) > (field2 :initarg :field2)) > (:report (lambda (c s) > (format s "~%MY ERROR: ~A - ~A~%" > (slot-value c :field1) > (slot-value c :field2))))) <snip> > Why? Two reasons. First, the slot in your condition are not named :FIELD1 and :FIELD2, but FIELD1 and FIELD2, so those calls to SLOT-VALUE won't work on any instances with slots so named: CL-USER> (defclass some-class () ((field1 :initarg :field1) (field2 :initarg :field2))) #<STANDARD-CLASS SOME-CLASS> CL-USER> (defparameter *instance* (make-instance 'some-class :field1 'a :field2 'b)) *INSTANCE* CL-USER> (slot-value *instance* :field1) When attempting to read the slot's value (slot-value), the slot :FIELD1 is missing from the object #<SOME-CLASS {524F9F11}>. [Condition of type SIMPLE-ERROR] ; Evaluation aborted CL-USER> (slot-value *instance* 'field1) A Second, SLOT-VALUE has no specified semantics for instances of condition classes [1], so you shouldn't expect this code to be portable, even if it happened to work on some implementation. Just define a couple of readers. Hope that helps, RmK [1] http://www.lisp.org/HyperSpec/Body/fun_slot-value.html |