Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure series of defs but don't expose to the outer scope all of them

Tags:

clojure

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?

like image 203
Marcus Junius Brutus Avatar asked Jan 15 '23 06:01

Marcus Junius Brutus


1 Answers

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.

like image 178
Alex Avatar answered Jan 30 '23 22:01

Alex