Created
June 22, 2022 21:03
-
-
Save hiredman/bc54694fbe15b9589b5a662ba88badd5 to your computer and use it in GitHub Desktop.
This file contains 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
(defmacro return% [a] | |
`(fn return-fn# [success# error#] | |
#(try | |
(success# ~a) | |
(catch Throwable t# | |
(error# t#))))) | |
(defn bind% [m b] | |
(fn a [success error] | |
#(m (fn x [value] ((b value) success error)) error))) | |
(defn try% [m handler] | |
(fn [success error] | |
(let [new-error (handler error)] | |
#(m success new-error)))) | |
(defmacro let% [bindings body] | |
(if (seq bindings) | |
(let [[name value & bindings] bindings] | |
(if (= name '!) | |
`(do ~value (let% ~bindings ~body)) | |
`(bind% ~value (fn bindfn# [~name] (let% ~bindings ~body))))) | |
body)) | |
(def call-cc% identity) | |
(trampoline | |
(let% [[success error n] (call-cc% (fn [success error] | |
(success | |
[(fn [value] (return% (success value))) | |
(fn [value] (return% (error value))) | |
0]))) | |
_ (return% (prn n))] | |
(if (> 10 n) | |
(success [success error (inc n)]) | |
(return% nil))) | |
identity | |
prn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment