Skip to content

Instantly share code, notes, and snippets.

@d11wtq d11wtq/declare.clj
Last active Aug 29, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.