3

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.

4

2 回答 2

2

我不是专家,但这似乎是一个命名空间问题。我采用的解决方案是:

;; for REPL
user=> (ns user (:use clojure.contrib.math))
nil
user=> (sqrt 2)
1.4142135623730951
于 2011-07-06T07:43:55.310 回答
1

您应该在require之后放置refer,它将所有符号映射到当前命名空间

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

(sqrt 2)
(expt 2 3)

有关详细介绍,您可以阅读 wikibooks 文章。 http://en.wikibooks.org/wiki/Clojure_Programming/Concepts#Refer_and_Use

于 2011-09-16T19:35:06.000 回答