java – Clojure:协议中没有方法的实现

我试图在Clojure REPL中为RDF clj-plaza加载Clojure库,如下所示:

user=> (use 'plaza.rdf.core)
nil

我有一个名为plaza的文件夹,以及一个名为rdf的子文件夹和文件core.clj,据我所知,Clojure REPL可以加载库.

现在,如果我这样做

user=> (alter-root-rdf-ns “http://www.example.org/”)
"http://www.example.org"

而且,core.clj库正在报告它应该.
现在我做

(def e (document-to-model “http://www.snee.com/rdf/elvisimp.rdf” :xml))
java.lang.IllegalArgumentException: No implementation of method: :load-stream of protocol: #’plaza.rdf.core/RDFModel found for class: nil (NO_SOURCE_FILE:2)

如果我尝试f.ex,我会得到相同的结果.

(make-triples [["http://triple1" "http://triple2" "http://triple3"]])

在源代码(core.clj)中,在协议RDFModel中存在称为加载流的方法

(defprotocol RDFModel
  "Operations for the manipulation of RDF"
  ....
  (load-stream [model stream format] "Load triples from a stream")
  ....

并且实现了加载流

(defn document-to-model
  "Adds a set of triples read from a serialized document into a model"
  ([stream format]
    (load-stream *rdf-model* stream format)))

我似乎无法确定这里有什么问题,在源代码中它似乎都加起来了.

最佳答案
(defn document-to-model …)代码段不实现加载流;它实现了一个名为document-to-model的函数,该函数使用一堆参数调用load-stream,其中第一个 – * rdf-model * – 需要是RDFModel协议已扩展到的类型(或者它直接实现协议或相应的接口).

clj-plaza在命名空间plaza.rdf.implementations.sesame中提供了两个RDFModel实现(参见(deftype SesameModel …,源代码中的line 218)和plaza.rdf.implementations.jena(参见(deftype JenaModel …,line 167).要求它们应该足以引入所述实现;然后你可以使用适当类型的* rdf-model * s.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...