Skip to content

Instantly share code, notes, and snippets.

@fouric
Last active March 21, 2019 00:53
Show Gist options
  • Save fouric/595724587ecf6021ad4cfce4facf63dd to your computer and use it in GitHub Desktop.
Save fouric/595724587ecf6021ad4cfce4facf63dd to your computer and use it in GitHub Desktop.
(defclass animal ()
())
(defclass bear (animal)
((height :initarg :height)))
(defgeneric noise (animal))
(defmethod noise ((animal bear))
(format t "ROAR~%"))
(defgeneric run (machine))
(defgeneric does-not-understand (object message))
(defmethod does-not-understand ((object bear) message)
(format t "object ~s does not understand message ~s~%" object message))
(defmethod no-applicable-method :around (gf &rest args)
(format t "args: ~s~%" args)
(format t "first: ~s~%" (first args))
(format t "class-of: ~s~%" (class-of (first args)))
(if (find-method #'does-not-understand nil (list (class-of (first args)) (find-class t)) nil)
(apply #'does-not-understand (first args) (cons gf (rest args)))
(call-next-method)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment