简体   繁体   English

如何在莱宁根使用Clojure`use`函数?

[英]How do I use the Clojure `use` function in leiningen?

I am very new to both Clojure and Leiningen. 我对Clojure和Leiningen都很陌生。 I have installed Clojure on Windows at C:\\clojure-1.5.1 and leiningen-win-installer beta1 at C:\\.lein\\bin . 我已经在Windows的C:\\clojure-1.5.1上安装了Clojure,并在C:\\.lein\\bin安装了leiningen-win-installer beta1。

Now I am trying the example from Eric Rochester's book. 现在,我正在尝试埃里克·罗切斯特(Eric Rochester)的书中的示例。 I have included dependent libraries for Incanter in project.clj and also using dep. 我在project.clj中包括了Incanter的依赖库,也使用了dep。

How do I use the command (use 'incanter.core) ? 我如何使用命令(use 'incanter.core) I am getting 'use' is not recognized as an internal or external command . 我收到的'use' is not recognized as an internal or external command In addition, how do I use lein commands at user=> ? 另外,如何在user=>使用lein命令?

Edit - I forgot "lein deps" until I saw Mars's answer 编辑-我忘了“莱恩·德普斯”,直到看到火星的答案

Before you start lein repl, you have to make the project (with "lein new getting-data" or whatever is in the book). 开始lein repl之前,您必须制作项目(使用“ lein新的获取数据”或书中的内容)。

That makes a new directory, and in that directory you find and edit "project.clj" to include the dependencies (as shown in book). 这将创建一个新目录,然后在该目录中找到并编辑“ project.clj”以包含依赖项(如书中所示)。

cd into the directory that project.clj is in and run "lein deps" from the dos/powershell prompt. cd进入project.clj所在的目录,并从dos / powershell提示符下运行“ lein deps”。

THEN when you run lein repl, from within that same directory, at the user=> prompt, do 然后,当您在同一目录中的用户=>提示符下运行lein repl时,执行

(use 'incanter.core) 

and it will come back with "nil" and you'll be running. 它将返回“ nil”,您将开始运行。 You might want to first run some examples from the leiningen page to get more of a feel for lein. 您可能需要先从leiningen页面运行一些示例,以使您对lein有更多的了解。 You always type clojure commands at the "user=>" prompt, not at the "c:....>" prompt. 您总是在“ user =>”提示符下而不是在“ c:....>”提示符下键入clojure命令。

There's a bit of subtlety in Leiningen project.clj's. Leiningen project.clj的内容有些微妙。 I haven't found an easy introduction. 我还没有找到简单的介绍。 Levin Magruder's advice will no doubt get you started. 莱文·马格鲁德(Levin Magruder)的建议无疑会帮助您入门。 The basic idea is that once the project file is set up correctly, lein deps will go out and find the libraries you need, and put them in a place where lein repl can find them. 基本思想是,一旦正确设置了项目文件, lein deps就会出去查找所需的库,并将它们放在lein repl可以找到它们的地方。 Then use will work for the libraries that have been downloaded. 然后use将为已下载的库工作。 For more info, study of the detailed comments project.clj sample file may be helpful. 有关更多信息,研究详细注释project.clj示例文件可能会有所帮助。 (Not part of the answer to this question, but if you're having problems with use , you're likely to get tripped up by ns and filenames soon (I was): I recommend Colin Jones' introduction to ns and its options .) (回答这个问题的不是一部分,但如果你有问题use ,你可能会得到由绊倒ns和文件名顺(我):我建议科林·琼斯介绍, ns和它的选项 。 )

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

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