I am writing several methods to extract HTML for various elements. Each method has the same output, but does not have to have the same input.
The method for the game-board echo reply should also accept player (because each player sees only their parts)
(defmethod echo ((board game-board) (p player)) ... )
Repeating a space on board does not require a change for each player (this sending is actually done in the game-board method, which later calls echo in the space). Ideally, I could do
(defmethod echo ((space board-space)) ... ) (defmethod echo ((space empty-space)) ... )
It is also possible that I later came across an object that would need to know more than just the player in order to display correctly. Since there are already methods specializing in the same generic level, this will give an error
The generic function #<STANDARD-GENERIC-FUNCTION ECHO (4)> takes 2 required arguments;
It seems less than ideal to go back and call these methods echo-space , echo-board and so on.
Is there a canonical way to change other arguments based on a specialized object? Should I do something like
(defgeneric echo (thing &key player ...) ...)
or
(defgeneric echo (thing &rest other-args) ...)
? More generally, can someone point me to a decent defgeneric in particular? (I have read the relevant PCL chapters and some CLOS tutorials , but they do not cover the situation I am asking about here).
common-lisp clos
Inaimathi
source share