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.

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Excellent. Seamlessly works with Clojure scripts being embedded into Java apps for me too (I'm using Netbeans, with Clojure and Clojure-contrib accessed as "libraries")!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.