Skip to content

Instantly share code, notes, and snippets.

@friedbrice
Forked from fiddlerwoaroof/extend.js
Last active June 4, 2019 17:13
Show Gist options
  • Select an option

  • Save friedbrice/915addaf78b562c5038f12e6629c39f1 to your computer and use it in GitHub Desktop.

Select an option

Save friedbrice/915addaf78b562c5038f12e6629c39f1 to your computer and use it in GitHub Desktop.
Static typable EP solution
(defpackage :fwoar.extend
(:use :cl )
(:export ))
(in-package :fwoar.extend)
#| ------------- Begin Library ------------- |#
(defclass animal ()
())
(defclass turtle (animal)
())
#| -------------- End Library -------------- |#
(defclass cat (animal)
(#| cat-specific members here |#))
(defclass dog (animal)
(#| dog-specific members here |#))
(defgeneric greet (thing)
(:method ((thing animal))
(format *standard-output* "the animal is unresponsive~%"))
(:method ((thing dog))
(format *standard-output* "the dog wags its tail joyfully~%"))
(:method ((thing cat))
(format *standard-output* "the cat stands aloof~%")))
(defgeneric leave (thing)
(:method ((thing animal))
(format *standard-output* "the animal is unresponsive~%"))
(:method ((thing dog))
(format *standard-output* "the dog looks very sad~%"))
(:method ((thing cat))
(format *standard-output* "the cat purs happily~%")))
(defun main ()
(dolist (animal (list (make-instance 'cat)
(make-instance 'dog)
(make-instance 'turtle)))
(dolist (action (list 'greet 'leave))
(funcall action animal)))) #| ===>
FWOAR.EXTEND> (main)
the cat stands aloof
the cat purs happily
the dog wags its tail joyfully
the dog looks very sad
the animal is unresponsive
the animal is unresponsive
|#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment