开发者

loading clojure-contrib

I'm new to the whole JVM 开发者_如何学Gothing, 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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜