Skip to content

Instantly share code, notes, and snippets.

@einblicker
Created October 17, 2011 01:57
Show Gist options
  • Save einblicker/1291761 to your computer and use it in GitHub Desktop.
Save einblicker/1291761 to your computer and use it in GitHub Desktop.
reify/reflect 2
(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