loading clojure-contrib

为君一笑 提交于 2020-01-04 02:34:34

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/6582028/loading-clojure-contrib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!