Skip to content

Instantly share code, notes, and snippets.

@d11wtq
Last active August 29, 2015 14:21
Show Gist options
  • Save d11wtq/deb4197695dbe1040c92 to your computer and use it in GitHub Desktop.
Save d11wtq/deb4197695dbe1040c92 to your computer and use it in GitHub Desktop.
Implicit forward declarations for Clojure
(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))
@d11wtq
Copy link
Author

d11wtq commented May 27, 2015

I wish the Clojure compiler did this automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment