Clojure Can';不要创建系统协议
我正在写一封信。我计划的一部分是建立一个名为Clojure Can';不要创建系统协议,clojure,protocols,Clojure,Protocols,我正在写一封信。我计划的一部分是建立一个名为System的协议,系统必须满足该协议才能使用ECS 问题是,如果我试图创建一个名为System的协议,Clojure会抱怨;似乎是因为它与java.lang.System冲突 (ns entity.system) (defprotocol System ; Protocol methods) 屈服 CompilerException java.lang.RuntimeException:应为var,但系统映射到类java.lang.Syste
System
的协议,系统必须满足该协议才能使用ECS
问题是,如果我试图创建一个名为System
的协议,Clojure会抱怨;似乎是因为它与java.lang.System
冲突
(ns entity.system)
(defprotocol System
; Protocol methods)
屈服
CompilerException java.lang.RuntimeException:应为var,但系统映射到类java.lang.System,编译:(C:\Users\slomi\IdeaProjects\entity\src\entity\System.clj:3:1)
我尝试通过添加(:refereclojure:exclude[System])
和(:refereclojure:exclude[java.lang.System])
来排除系统,但都没有做任何事情;我又收到了同样的错误
当然,我可以给它起个别的名字,但是System
似乎是最合适的名字,比如entity.entity-System/entity-System
或者甚至entity.System/entity-System
似乎太多余了
如何将java.lang.System
从名称空间中排除?您要查找的是ns unmap
(ns-unmap *ns* 'System)
(defprotocol System
(add [this that]))
(extend-protocol System
Long
(add [this that]
(format "%d + %d is %d" this that (+ this that))))
(add 2 3)
;;=> "2 + 3 is 5"
可爱。非常感谢。