Reputation: 27286
At the head of my clojure file I have a series of defs, some of which are only stepping-stone defs, i.e. are not meant to be used further down the file. I.e.
def src-folder (File. "src")
def lib-folder (File. src-folder "lib")
def dist-folder (File. src-folder "bin")
;; I only care for the lib-folder and dist-folder beyond this point
What's the right way to do that in Clojure?
Upvotes: 4
Views: 61
Reputation: 13961
Use let
instead of def
for the first throw-away definition, and nest the remaining def
calls inside the let
:
(let [root-dir (File. "projects/my-project")
src-folder (File. root-dir "src")]
(def lib-folder (File. src-folder "lib"))
(def dist-folder (File. src-folder "bin")))
The value of the src-folder
local binding is discarded after the let
is evaluated, leaving only the lib-folder
and dist-folder
vars accessible to the rest of the program.
Upvotes: 5
Reputation: 5159
If they were defn
s (i.e. functions) you could simply use defn-
to make a private function.
For def
s you have to explicitly set them as private:
(def ^:private src-folder (File. "src"))
Upvotes: 4