-
-
Save friedbrice/915addaf78b562c5038f12e6629c39f1 to your computer and use it in GitHub Desktop.
Static typable EP solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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