Created
August 8, 2015 22:41
-
-
Save selfsame/0dcbf71856d1735aac18 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
| (declare look) | |
| (def test-item | |
| {:noun "chest" :material "wooden" | |
| :closed false | |
| :container | |
| [{:noun "spoon" :material "tin"} | |
| {:noun "bag" :material "leather" | |
| :closed true | |
| :container | |
| [{:noun "coin" :material "copper"} | |
| {:noun "coin" :material "gold"}]}]}) | |
| (rule describe [^:vector? o] {} | |
| (unseq "it contains" (map write-name o))) | |
| (rule describe [^empty? o] {} "it's empty") | |
| (rule describe [o] | |
| {o (a (non :closed) :container)} | |
| "inside " (describe (:container o))) | |
| (rule describe [o] | |
| {o (a :closed :container)} | |
| "it is closed") | |
| (rule item-state [o] | |
| {o :contents} | |
| (if (:closed o) "closed" "open")) | |
| (rule write-article [o] {} "the") | |
| (rule write-adjectives [o] {} | |
| (interpose "," | |
| (unseq | |
| (item-state o) | |
| (:material o)))) | |
| (rule write-name [o] {} "thing") | |
| (rule write-name [^:noun o] {} (:noun o)) | |
| (rule look [o] {} | |
| "You don't see anything.") | |
| (rule look [^map? o] {} | |
| (unseq | |
| "You look at" | |
| (write-article o) | |
| (write-adjectives o) | |
| (write-name o) "." | |
| (describe o))) | |
| (look 7) | |
| (look test-item) | |
| (look (first (:container test-item))) | |
Author
selfsame
commented
Aug 8, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment