Created
May 26, 2015 09:45
-
-
Save farhaven/6f74ff641a0e7c4a1846 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
(defmacro let+ [vars &rest body] | |
(setv cover []) | |
(setv uncover []) | |
(for* [v vars] | |
(if (instance? list v) | |
(do | |
(setv name (gensym (first v))) | |
(.append cover `(try | |
(setv ~name ~(first v)) | |
(except))) | |
(.append cover `(setv ~(first v) ~(second v))) | |
(.append uncover `(try | |
(setv ~(first v) ~name) | |
(except))) | |
(.append uncover `(try | |
(del ~name) | |
(except)))) | |
(do | |
(setv name (gensym v)) | |
(.append cover `(try | |
(setv ~name ~v) | |
(except))) | |
(.append cover `(setv ~v None)) | |
(.append uncover `(try | |
(setv ~v ~name) | |
(except))) | |
(.append uncover `(try | |
(del ~name) | |
(except)))))) | |
`(do | |
~@cover | |
(try | |
(do ~@body) | |
(finally | |
~@uncover)))) | |
(setv x 0) | |
(print x) | |
(let+ [[x 1]] | |
; (print (dir)) | |
; (print y) | |
(print x)) | |
(print x) | |
(print (let+ [] 'foo)) | |
(let+ [z] | |
(print z)) | |
(try | |
foo | |
(except)) | |
(let+ [[a 2]] | |
(print a) | |
(let+ [[a 3]] | |
(print a)) | |
(print a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment