Last active
August 29, 2015 14:21
-
-
Save d11wtq/deb4197695dbe1040c92 to your computer and use it in GitHub Desktop.
Implicit forward declarations for Clojure
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
(defn def? | |
[[a b]] | |
(if (#{'defn 'def} a) b)) | |
(defmacro progn | |
[& sexps] | |
(let [names (->> sexps (filter def?) (map def?))] | |
`(do | |
(declare ~@names) | |
~@sexps))) | |
(progn | |
(defn x | |
[n] | |
(* (y n) n)) | |
(defn y | |
[n] | |
(* z n)) | |
(def z 3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wish the Clojure compiler did this automatically.