load-file

added
1.0

ns
clojure.core

type
function

(load-file name)

Sequentially read and evaluate the set of forms contained in the file.

                ;; Very useful from a REPL
;; Paths are specified as strings using canonical file path notation 
;; (rather than clojure-style namespaces dependent on the JVM classpath).
;; The working directory is set to wherever you invoked the JVM from, 
;; likely the project root.

(load-file "src/mylib/core.clj")

;; now you can go and evaluate vars defined in that file.
            
                ;; file located at src/address_book/core.clj
;; current dir is src/..

(load-file "src/address_book/core.clj")
            
                ;; create a clojure file on the fly using spit
;; then load it into the REPL and use its function

user=> (spit "mycode.clj" "(defn doub [x] (* x 2))")
nil
user=> (load-file "mycode.clj")
#'user/doub
user=> (doub 23)
46