From: Paul B. <pb...@ol...> - 2013-06-26 22:02:41
|
On 06/26/2013 11:56 AM, Christophe Rhodes wrote: > Paul Bowyer <pb...@ol...> writes: > >> I do, however, have a gripe with the sbcl compiler. The fact that the >> faulty code would compile even though it had errors is bothersome. > Well, this is a bit more subtle, but: the code is not /a priori/ faulty. > The issue here is that in the particular case of defclass, and a few > other defining forms mostly related to CLOS, the operators are > extensible: it is possible to define metaclasses such that arbitrary > extra information can be passed after the slots list. > > So in this case: > > (defclass clx-class (standard-class) > ((forgd :initarg forgd) > (grps :initarg grps))) > > (defmethod sb-mop:validate-superclass ((c clx-class) (s standard-class)) > t) > > (defclass clx-window () > () > (:metaclass clx-class)) > > (defclass clx-entry-dialog (clx-window) > ((par-inst :accessor par-inst :initarg :parent-instance) > (wnttl :accessor wnttl :initform nil :initarg :win-title) > (vinfo :accessor vinfo :initform nil :initarg :var-info) > (varlst :accessor varlst :initform nil :initarg :var-list) > (tab-idx :accessor tab-idx :initform 1 :initarg :tab-index)) > (forgd :accessor forgd #||:initform *white* :initarg :foreground||# ) > (grps :accessor grps #||:initform nil :initarg :groups||# ) > (:metaclass clx-class)) > > is legal, compiles, and the clx-entry-dialog class can be instantiated. > > Now, it might be possible to determine the conditions under which no > unknown extension arguments to defclass are legal, and it might also be > possible to determine them sufficiently confidently that it would be > practical to give an earlier warning when encountering them in the > circumstances such as in your initial message. But it's not completely > trivial, and this might be one of the cases where a little bit of bother > for a relative newcomer, unfortunate though it might be, is something > that has to be endured. (If you were motivated enough to remove the > bother for the next person, I'd suggest first statically computing the > valid initialization arguments for STANDARD-CLASS and then emitting a > warning at DEFCLASS-expansion-time if there are initialization arguments > generated that are not in that set.) > > Best wishes, > > Christophe > Hello Christophe, Thanks for the explanation. I see that it might be more trouble than it's worth to add checks to the class definition to catch silly errors like mine. Maybe after I get more experience with lisp in general and sbcl in particular, I might try your suggestion with STANDARD-CLASS just to see how much effort that entails. Paul Bowyer |