Created
October 17, 2011 01:57
-
-
Save einblicker/1291761 to your computer and use it in GitHub Desktop.
reify/reflect 2
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
(use 'delimc.core) | |
(use 'clojure.contrib.monads) | |
(defmacro reify [thunk] | |
`(reset | |
(m-result ~thunk))) | |
(defmacro reflect [meaning] | |
`(shift k# | |
(m-bind ~meaning k#))) | |
(with-monad sequence-m | |
(reify (list (reflect '(1 2 3)) (reflect '(4 5 6))))) | |
(with-monad (writer-m ()) | |
(reify | |
(letfn [(fact [acc n] | |
(reflect (write n)) | |
(if (= 1 n) | |
acc | |
(fact (+ acc n) (dec n))))] | |
;↑recurにできない | |
(fact 1 10)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment