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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With