To compile whole set of classes we write " Library/* " (in Java). what is clojure equivalent to this?
Compiling using REPL.
In general you have 3 ways of loading files/libraries into the REPL:
Use is the most powerfull (and also most dangerous).
Require tells the REPL that you are going to use items from that namespace. For example:
(require 'clojure.string)
allows you to do:
(clojure.string/split "hi, reader" #",")
Use does the same as Require, however use also includes all the vars of the ns into your current namespace.
Import is used with java libraries, like so:
(import 'java.util.Date)
so you can
(Date.)
Require (and therefore Use) uses a number of other functions "under the hood":
(require '[clojure.test :as test] :verbose)
(clojure.core/load "/clojure/template")
(clojure.core/load "/clojure/walk")
(clojure.core/in-ns 'clojure.template)
(clojure.core/alias 'walk 'clojure.walk)
(clojure.core/in-ns 'clojure.test)
(clojure.core/alias 'temp 'clojure.template)
(clojure.core/load "/clojure/test")
So you can also simulate require by doing these steps manually.
Another interesting function is load-file
(load-file "src/mylib/core.clj")
and load
(load "address_book/core")
these load Clojure code from resources in classpath. A path is interpreted as classpath-relative if it begins with a slash or relative to the root directory for the current namespace otherwise.
If you want to load anything more complex then say 2 or 3 files, I seriously recommend using Leiningen.
edit: you might also want to use:
(add-classpath "file:///home/../.../src/")
To easily add files to the classpath, so you can use them with require.
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