I just learned this five minutes ago. I wanted to use the clojure-csv library, here's what I did using Leiningen
Make a new leiningen project
lein new app csvtest
Now I have a folder called
csvtest/
. In thecsvtest/project.clj
file, edit the dependencies section to add the clojure-csv github path and a version. I'm not quite sure how the versioning works to be honest::dependencies [[org.clojure/clojure "1.5.1"] [clojure-csv/clojure-csv "2.0.1"]]
Now run
lein deps
to automagically download any unresolved dependencies for your project$ lein deps ... Retrieving clojure-csv/clojure-csv/2.0.1/clojure-csv-2.0.1.pom from clojars ...
Now edit
csvtest/src/csvtest/core.clj
. Make it look like this:Edit: (Based on sveri's comment I changed
:use closjure-csv.core
to the:require
line)(ns csvtest.core (:gen-class) (:require [clojure-csv.core :refer [parse-csv]])) (defn -main "I don't do a whole lot ... yet." [& args] (println (parse-csv "1,2,3,hello,world")))
You have to add the
(:require [clojure-csv.core :refer [parse-csv]])
line to yourns
, and in main it callsparse-csv
, one of the functions provided by the library. From reading, it looks like:use
is depreciated in favor of:require
.Note: For anyone coming from python (like me), it looks like doing
:use clojure-csv.core
is akin tofrom closure_csv import *
, which is bad practice in python as well. And(:require [clojure-csv.core :refer [parse-csv]])
is likefrom clojure_csv import parse_csv
Run the project with
lein run
. My output was$ lein run ([1 2 3 hello world])
I hope that helps!