Prev: Anybody mind to translate this Felleisen quote from German to English
Next: Macros and anonymous functions
From: ccc31807 on 24 Feb 2010 18:08 Learning Lisp is like pulling teeth, except more painful! Here is a code snippet copied directly from Figure 11.2, page 178, of Graham's 'ANSI Common Lisp': (defclass rec () (height width)) (defclass cir () (radius)) (defmethod area ((x rec)) (* (slot-value x 'height) (slot-value x 'width ))) (defmethod area ((x cir)) (* pi (expt (slot-value x 'radius) 2))) Here is the error message gives when I try to compile this: NO-APPLICABLE-METHOD: When calling #<GENERIC-FUNCTION FIND-METHOD> with arguments (#<COMPILED-CLOSURE AREA> NIL (REC) NIL), no method is applicable. [Condition of type METHOD-CALL-TYPE-ERROR] I've tried the usual sources of help, including Keene, Lamkins, and Seibel, and the HyperSpec, but I still can't figure out why this won't compile. Like I said, more painful than pulling teeth ... unless somebody notes that I made a stupid typo that I have overlooked. CC.
From: Zach Beane on 24 Feb 2010 18:28 > Here is a code snippet copied directly from Figure 11.2, page 178, of > Graham's 'ANSI Common Lisp': > > (defclass rec () > (height width)) > (defclass cir () > (radius)) > (defmethod area ((x rec)) > (* (slot-value x 'height) (slot-value x 'width ))) > (defmethod area ((x cir)) > (* pi (expt (slot-value x 'radius) 2))) > > Here is the error message gives when I try to compile this: I copied your snippet into a file called "scratch.lisp" and did (compile-file "scratch.lisp") and didn't get any errors. What kind of compiling did you do that triggered an error? Zach
From: refun on 24 Feb 2010 18:41 In article <5bf2d29e-ea74-4c9c-a67d-e10c46b8e14f(a)d27g2000yqf.googlegroups.com>, cartercc(a)gmail.com says... > > Learning Lisp is like pulling teeth, except more painful! > > Here is a code snippet copied directly from Figure 11.2, page 178, of > Graham's 'ANSI Common Lisp': > > (defclass rec () > (height width)) > (defclass cir () > (radius)) > (defmethod area ((x rec)) > (* (slot-value x 'height) (slot-value x 'width ))) > (defmethod area ((x cir)) > (* pi (expt (slot-value x 'radius) 2))) > > Here is the error message gives when I try to compile this: > > NO-APPLICABLE-METHOD: When calling #<GENERIC-FUNCTION FIND-METHOD> > with arguments (#<COMPILED-CLOSURE > AREA> > NIL (REC) NIL), no method is applicable. > [Condition of type METHOD-CALL-TYPE-ERROR] > > I've tried the usual sources of help, including Keene, Lamkins, and > Seibel, and the HyperSpec, but I still can't figure out why this won't > compile. > > Like I said, more painful than pulling teeth ... unless somebody notes > that I made a stupid typo that I have overlooked. > > CC. Your code works fine here (on SBCL). I don't see anything weird with it, except that you didn't define any accessors or initargs. Here's some test code: (let ((rec (make-instance 'rec)) (cir (make-instance 'cir))) (with-slots (height width) rec (setf height 10 width 20) (setf (slot-value cir 'radius) 30) (values (area rec) (area cir)))) ;=>200, 2827.4333882308138d0 Or rewritten with initargs/accessors. (defclass rectangle () ((height :initarg :height :accessor height) (width :initarg :width :accessor width))) (defclass circle () ((radius :initarg :radius :accessor radius))) (defmethod area ((x rectangle)) (* (height x) (width x))) (defmethod area ((x circle)) (* pi (expt (radius x) 2))) (let ((rec (make-instance 'rectangle :height 10 :width 20)) (cir (make-instance 'circle :radius 30))) (values (area rec) (area cir))) ;=>200, 2827.4333882308138d0
From: Tim Bradshaw on 24 Feb 2010 19:26 On 2010-02-24 23:08:02 +0000, ccc31807 said: > (defclass rec () > (height width)) > (defclass cir () > (radius)) > (defmethod area ((x rec)) > (* (slot-value x 'height) (slot-value x 'width ))) > (defmethod area ((x cir)) > (* pi (expt (slot-value x 'radius) 2))) > > Here is the error message gives when I try to compile this: What do you mean by "when I try to compile this"? If you put the above in a file and compile it with COMPILE-FILE I think this should definitely be fine.
From: Patrick May on 24 Feb 2010 20:12
ccc31807 <cartercc(a)gmail.com> writes: > (defclass rec () > (height width)) > (defclass cir () > (radius)) > (defmethod area ((x rec)) > (* (slot-value x 'height) (slot-value x 'width ))) > (defmethod area ((x cir)) > (* pi (expt (slot-value x 'radius) 2))) > > Here is the error message gives when I try to compile this: > > NO-APPLICABLE-METHOD: When calling #<GENERIC-FUNCTION FIND-METHOD> > with arguments (#<COMPILED-CLOSURE > AREA> > NIL (REC) NIL), no method is applicable. > [Condition of type METHOD-CALL-TYPE-ERROR] I cut and pasted that into SBCL on OSX and it was fine. What Lisp are you using? Regards, Patrick ------------------------------------------------------------------------ http://www.softwarematters.org Large scale, mission-critical, distributed OO systems design and implementation. (C++, Java, Common Lisp, Jini, middleware, SOA) |