Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can new clojure libraries be loaded in the repl

Tags:

clojure

So I have this workflow problem:

I'm happily typing away on my clojure project repl and realise that i need another library that is not in my project.clj, say in this case, i needed the tools.cli library.

I open up project.clj in my editor and add in an entry to the :dependencies

     [org.clojure/tools.cli "0.2.1"]

Then, within the project directory, I type lein deps in the shell to pull in the necessary libraries

After the project dependencies are pulled, technically all the class files are already there ready to be loaded, but if I go back to my repl and type:

> (use 'tools.cli)

I get this:

=>> FileNotFoundException Could not locate tools/cli__init.class
  or tools/cli.clj on classpath:   clojure.lang.RT.load (RT.java:432)

So I would have to restart my repl, wasting a whole heap of time reconfiguring the state of the repl to where I was before I needed the library.

Is there a way to just load in the library dynamically? eg, after I run lein deps I just go back to the repl and type:

> (load-library "tools.cli") 
> (use 'tools.cli)

Thanks in advance

like image 790
zcaudate Avatar asked Jul 25 '12 01:07

zcaudate


People also ask

What is Clojure REPL?

A Clojure REPL (standing for Read-Eval-Print Loop) is a programming environment which enables the programmer to interact with a running Clojure program and modify it, by evaluating one code expression at a time.

How do I start Clojure REPL?

Starting a REPL Session To start a REPL session in Eclipse, click the Menu option, go to Run As → Clojure Application. This will start a new REPL session in a separate window along with the console output.


2 Answers

Pomegranate is for you:

https://github.com/cemerick/pomegranate

It supports download and addition of new dependencies at runtime, e.g.:

(add-dependencies :coordinates '[[incanter "1.2.3"]]
                  :repositories (merge cemerick.pomegranate.aether/maven-central
                                       {"clojars" "http://clojars.org/repo"}))
like image 84
mikera Avatar answered Sep 23 '22 02:09

mikera


Will something like this work for you?

https://groups.google.com/d/msg/clojure/AJXqbpGMQw4/0-7-3pXRwGkJ

There is also clojure.core/add-classpath, but it's deprecated.

http://clojuredocs.org/clojure_core/clojure.core/add-classpath

like image 25
brool Avatar answered Sep 21 '22 02:09

brool