Reputation: 45
When I call (draw win) I get an error the "generic function can't find applicable method. I have just gotten into CLOS and I am using sdl2kit to simply render a window.
(defclass game-window (kit.sdl2:window)
((rotation :initform 0.0)))
(defmethod render ((win game-window))
(with-slots (rotation) win
(gl:load-identity)
(gl:rotate rotation 0 0 1)
(gl:clear-color 0.0 0.0 1.0 1.0)
(gl:clear :color-buffer)
(gl:begin :triangles)
(gl:color 1.0 0.0 0.0)
(gl:vertex 0.0 1.0)
(gl:vertex -1.0 -1.0)
(gl:vertex 1.0 -1.0)
(gl:end)))
(defgeneric draw(win)
(:documentation "draw window"))
(defun main ()
(let (( win (make-instance 'game-window)))
(draw win)))
Upvotes: 0
Views: 1106
Reputation: 4360
So there are two issues. One is an English language issue (you have to be super careful because every English word is overloaded with multiple programming meanings. Eg when you write “call” it isn’t clear whether you mean “name” or “invoke/apply”.) but that doesn’t really matter
The other issue is that you don’t know what a generic function is. Here is a quick explainer.
A generic function has (roughly) three parts:
A method has three parts
nil
)When you call a generic function this happens:
Steps 2-4 are typically cached.
Step 3 comes in roughly two forms:
around
methods are calledbefore
methodscall-next-method
)after
methodsaround
methodsand
or progn
or append
.To add a method to the set of methods of a generic function one typically uses defmethod
with the same name as the generic function
Upvotes: 1