From: Bruno H. <br...@cl...> - 2011-08-01 23:38:56
|
Hi Sam, > After all, all simple conditions are internal to clisp No. Users can define their own subclasses of SIMPLE-CONDITION, see <http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/contyp_simple-condition.html> And they can define their own PRINT-OBJECT methods on their own SIMPLE-CONDITION subclasses. > defmethod print-object :around ((condition simple-condition) stream) cf. condition.lisp line 478 > Why is it an ":around" method? Let's look at the applicable methods: > (define-condition simple-foo (simple-error) () (:report report-foo)) SIMPLE-FOO > (compute-applicable-methods-using-classes #'print-object (list (find-class 'simple-foo) (find-class 't))) (#<STANDARD-METHOD (#<STANDARD-CLASS SIMPLE-FOO> #<BUILT-IN-CLASS T>)> #<STANDARD-METHOD :AROUND (#<STANDARD-CLASS SIMPLE-CONDITION> #<BUILT-IN-CLASS T>)> #<STANDARD-METHOD (#<STANDARD-CLASS CONDITION> #<BUILT-IN-CLASS T>)> #<STANDARD-METHOD (#<STANDARD-CLASS STANDARD-OBJECT> #<BUILT-IN-CLASS T>)> ) If it were a primary method instead of an around method, the result would be > (compute-applicable-methods-using-classes #'print-object (list (find-class 'simple-foo) (find-class 't))) (#<STANDARD-METHOD (#<STANDARD-CLASS SIMPLE-FOO> #<BUILT-IN-CLASS T>)> #<STANDARD-METHOD (#<STANDARD-CLASS SIMPLE-CONDITION> #<BUILT-IN-CLASS T>)> #<STANDARD-METHOD (#<STANDARD-CLASS CONDITION> #<BUILT-IN-CLASS T>)> #<STANDARD-METHOD (#<STANDARD-CLASS STANDARD-OBJECT> #<BUILT-IN-CLASS T>)> ) > If yes, wouldn't it be better to use a regular method Indeed, it seems that if you use a primary method, the report-function of SIMPLE-FOO will take precedence over the printing with (apply #'format stream (simple-condition-format-control condition) (simple-condition-format-arguments condition)) Whereas in the current state, through :AROUND, the printing with (apply #'format stream (simple-condition-format-control condition) (simple-condition-format-arguments condition)) takes precedence over the :REPORT option of SIMPLE-FOO. > (or even a :report argument A :report argument is equivalent to a defmethod anyway, see <http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/mac_define-condition.html> > I think this would add robustness because > - the code becomes cleaner It would definitely be a change in behaviour. The comment "Instead we define a print-object method which will be executed regardless of the condition type's CPL" indicates that the code is meant to provide some specific behaviour, regarding the condition type's CPL. Only I don't know if that specific behaviour is the one CLHS wants. > - we do make sure that a careless developer does not add a print-object > method which overrides our preferred one. Compliant programs are not allowed to add a :AROUND method for PRINT-OBJECT on SIMPLE-CONDITION, and I think clisp warns about this already. Bruno -- In memoriam Marie Trintignant <http://en.wikipedia.org/wiki/Marie_Trintignant> |