How do I use the Clojure `use` function in leiningen?

泪湿孤枕 提交于 2019-12-12 06:39:54

问题


I am very new to both Clojure and Leiningen. I have installed Clojure on Windows at C:\clojure-1.5.1 and leiningen-win-installer beta1 at C:\.lein\bin.

Now I am trying the example from Eric Rochester's book. I have included dependent libraries for Incanter in project.clj and also using dep.

How do I use the command (use 'incanter.core)? I am getting 'use' is not recognized as an internal or external command. In addition, how do I use lein commands at user=>?


回答1:


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).

That makes a new directory, and in that directory you find and edit "project.clj" to include the dependencies (as shown in book).

cd into the directory that project.clj is in and run "lein deps" from the dos/powershell prompt.

THEN when you run lein repl, from within that same directory, at the user=> prompt, do

(use 'incanter.core) 

and it will come back with "nil" and you'll be running. You might want to first run some examples from the leiningen page to get more of a feel for lein. You always type clojure commands at the "user=>" prompt, not at the "c:....>" prompt.




回答2:


There's a bit of subtlety in Leiningen project.clj's. I haven't found an easy introduction. Levin Magruder's advice will no doubt get you started. 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. Then use will work for the libraries that have been downloaded. For more info, study of the detailed comments project.clj sample file may be helpful. (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.)



来源:https://stackoverflow.com/questions/20813742/how-do-i-use-the-clojure-use-function-in-leiningen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!