简体   繁体   English

如何在repl中加载新的clojure库

[英]How can new clojure libraries be loaded in the repl

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. 我很乐意在我的clojure项目repl上输入,并意识到我需要另一个不在我的project.clj库,在这种情况下说,我需要tools.cli库。

I open up project.clj in my editor and add in an entry to the :dependencies 我在编辑器中打开project.clj并添加了一个条目: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 然后,在项目目录中,我在shell中键入lein deps以引入必要的库

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: 在拉动项目依赖项之后,从技术上讲,所有类文件都已准备好加载,但是如果我回到我的repl并输入:

> (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. 所以我必须重新启动我的repl,浪费了一大堆时间将repl的状态重新配置到我需要库之前的位置。

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: 例如,在我运行lein deps我只需返回到repl并输入:

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

Thanks in advance 提前致谢

Pomegranate is for you: 石榴适合你:

https://github.com/cemerick/pomegranate https://github.com/cemerick/pomegranate

It supports download and addition of new dependencies at runtime, eg: 它支持在运行时下载和添加新的依赖项,例如:

(add-dependencies :coordinates '[[incanter "1.2.3"]]
                  :repositories (merge cemerick.pomegranate.aether/maven-central
                                       {"clojars" "http://clojars.org/repo"}))

Will something like this work for you? 这样的事情会对你有用吗?

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

There is also clojure.core/add-classpath, but it's deprecated. 还有clojure.core / add-classpath,但它已被弃用。

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

You can try out one library in the repl using lein-try . 您可以使用lein-try在repl中试用一个库。

~/.lein/profiles.clj : ~/.lein/profiles.clj

{:user {:plugins [[lein-try "0.4.3"]]}}

command line : command line

$ lein try clj-time "0.5.1"
Fetching dependencies... (takes a while the first time)
lein-try loaded [clj-time "0.5.1"]

nREPL server started on port 57036
REPL-y 0.2.0
Clojure 1.5.1
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)

user=>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM