Unable to resolve symbol: is in this context

会有一股神秘感。 提交于 2019-12-12 07:49:50

问题


I'm brand new to Clojure, and I am having a bit of trouble getting unit tests running.

(ns com.bluepojo.scratch
  (:require clojure.test))

(defn add-one
  ([x] (+ x 1))
  )

(is (= (add-one 3) 4))

gives:

java.lang.Exception: Unable to resolve symbol: is in this context

What am I missing?

Update:

This works:

(clojure.test/is (= (add-one 3) 4))

How do I make it so that I don't have to declare clojure.test before the is?


回答1:


Your use of the ns macro is not quite correct and you have several options to fix it. I would suggest one of

1. Alias clojure.test to something shorter

(ns com.bluepojo.scratch
  (:require [clojure.test :as test))

(defn add-one
  ([x] (+ x 1)))

(test/is (= (add-one 3) 4))

2. Use use

(ns com.bluepojo.scratch
  (:use [clojure.test :only [is]]))

(defn add-one
  ([x] (+ x 1)))

(is (= (add-one 3) 4))

Take a look at this article which explains this at some length




回答2:


Just use require and refer

(ns com.bluepojo.scratch
  (:require [clojure.test :refer :all))

Then simply

(is (= (add-one 3) 4))
(are ...)

:refer also takes a list of symbols to refer from the namespace (e.g. :refer [is are]).



来源:https://stackoverflow.com/questions/4457321/unable-to-resolve-symbol-is-in-this-context

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