Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java equivalent asterisk (*) in clojure?

Tags:

java

clojure

To compile whole set of classes we write " Library/* " (in Java). what is clojure equivalent to this?
Compiling using REPL.

like image 319
vikbehal Avatar asked May 19 '26 11:05

vikbehal


1 Answers

In general you have 3 ways of loading files/libraries into the REPL:

  • Use
  • Require
  • Import

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.

like image 59
Sander Avatar answered May 22 '26 02:05

Sander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!