On Thu, Nov 7, 2013 at 5:18 AM, Starry SHI <starr...@gmail.com> wrote:
> Hi, I am new to clojure and I find lein REPL very convenient to use. But I
> have one question: in REPL, how to include functions defined in other
> libraries and call them in my clojure code?

As Marshall indicated, you need to edit your project.clj file - which
in turn means you need to have such a file, which you create with:
lein new myproject (or whatever you want to call it). Leiningen will
create a folder called myproject containing a bunch of stuff including
project.clj. If you run `lein repl` inside the myproject folder, it
will have access to whatever libraries you've added to project.clj.

Example:

> lein new math
Generating a project called math based on the 'default' template.
To see other templates (app, lein plugin, etc), try `lein help new`.
> cd math
> cat project.clj
(defproject math "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME";
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]])

See :dependencies? That's where you'll add new libraries. You asked
about clojure.contrib.math but that is old and no longer maintained,
so for contrib libraries, consult this page:

http://dev.clojure.org/display/community/Where+Did+Clojure.Contrib+Go

(for other non-core/non-contrib libraries, you would search
http://clojars.org as Marshall indicated)

You'll see:

* clojure.contrib.math
  * Migrated to clojure.math.numeric-tower - lead Mark Engelberg.
  * Status: latest build status, latest release on Maven, report bugs.

And if you go to https://github.com/clojure/math.numeric-tower/ (which
is where clojure.math.numeric-tower links to) you'll see:

Leiningen dependency information:

    [org.clojure/math.numeric-tower "0.0.2"]

So we'll edit project.clj to include that... and get:

> cat project.clj
(defproject math "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME";
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [org.clojure/math.numeric-tower "0.0.2"]])

Be careful about the brackets!

Now we'll start a repl:

> lein repl
...
user=> (require '[clojure.math.numeric-tower :as math])
nil
user=> (math/sqrt 1234)
35.12833614050059
user=>

Hope that helps?
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to