如何在当前命名空间中检查符号是否可解析?

时间:2009-09-11 18:26:42

标签: clojure

我想检查当前命名空间中符号是否可解析。这样做的规范方法是什么?

2 个答案:

答案 0 :(得分:4)

再次筛选API文档之后,我偶然发现了可能适合的功能:

; Returns the var or Class to which the symbol
; will be resolved in the current namespace, else nil.
  (resolve 'foo)

; see also:
  (ns-resolve *a-namespace* 'foo)

答案 1 :(得分:3)

看看this page。例如

(ns-map *ns*)

将为您提供当前命名空间中绑定的映射。您可以检查此地图以确定您的符号是否是地图中的键,

(defn resolvable? [sym] 
  (contains? (ns-map *ns*) sym))

我不知道这是否是规范方式。