Skip to content

Instantly share code, notes, and snippets.

@masatoi
Created February 3, 2020 15:24
Show Gist options
  • Save masatoi/45f8b5ad446b4fb6e1c0167737e57998 to your computer and use it in GitHub Desktop.
Save masatoi/45f8b5ad446b4fb6e1c0167737e57998 to your computer and use it in GitHub Desktop.
call-next-method復習
(defclass parent () ())
(defclass child (parent) ())
(defparameter p1 (make-instance 'parent))
(defparameter c1 (make-instance 'child))
(defgeneric say (self word))
(defmethod say ((self parent) word)
(format t "~A says ~A~%" self word))
(defmethod say ((self child) word)
(format t "In child. ")
(call-next-method))
(say p1 "hoge") ; => #<PARENT {1006518C23}> says hoge
(say c1 "mage") ; => In child. #<CHILD {1006528C23}> says mage
(defmethod say ((self child) word)
(format t "In child. ")
(call-next-method self (string-upcase word)))
(say p1 "hoge") ; => #<PARENT {1006518C23}> says hoge
(say c1 "mage") ; => In child. #<CHILD {1006528C23}> says MAGE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment