loading clojure-contrib

2019-07-02 15:00发布

I'm new to the whole JVM thing, and trying to play with clojure. I'm attempting to load clojure-contrib and failing:

# in bash
$ java -cp /path/to/clojure.jar:/path/to/contrib.jar clojure.main

# in REPL
user=> (require 'clojure.contrib.math)
nil
user=> (sqrt 2)
java.lang.Exception: Unable to resolve symbol: sqrt in this context (NO_SOURCE_FILE:10)

Any pointers will be great - thanks.

2条回答
ゆ 、 Hurt°
2楼-- · 2019-07-02 15:24

You should put refer after require which will map all the symbols into current namespace

(require 'clojure.contrib.math)
(refer 'clojure.contrib.math)

(sqrt 2)
(expt 2 3)

For detailed intro you may read wikibooks article. http://en.wikibooks.org/wiki/Clojure_Programming/Concepts#Refer_and_Use

查看更多
Ridiculous、
3楼-- · 2019-07-02 15:47

I'm no expert, but it seemed like a namespace issue. The solution I employed was this:

;; for REPL
user=> (ns user (:use clojure.contrib.math))
nil
user=> (sqrt 2)
1.4142135623730951
查看更多
登录 后发表回答