Created
September 16, 2010 14:27
-
-
Save manuel/582510 to your computer and use it in GitHub Desktop.
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
(defclass (term A)) | |
(defclass literal-term ((term number)) | |
((value number)) | |
(:constructor ((value number)))) | |
(defclass is-zero-term ((term boolean)) | |
((subterm (term number))) | |
(:constructor ((subterm (term number))))) | |
(defclass (if-term A) ((term A)) | |
((test-term (term boolean)) | |
(then-term (term A)) | |
(else-term (term A))) | |
(:constructor ((test-term (term boolean)) (then-term (term A)) (else-term (term A))))) | |
(defgeneric eval ((term (term A)) -> A)) | |
(defmethod eval ((term literal-term) -> number) | |
(.value term)) | |
(defmethod eval ((term is-zero-term) -> boolean) | |
(= 0 (.value (.subterm term)))) | |
(defmethod eval ((term (if-term A) -> A)) | |
(if (eval (.test-term term)) | |
(eval (.then-term term)) | |
(eval (.else-term term)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment