无法创建系统协议

Car*_*ate 3 protocols clojure

我正在编写一个实体组件系统。我的部分计划是制定一个称为System系统必须满足的协议才能使用 ECS。

问题是,如果我尝试创建一个名为System;的协议,Clojure 会抱怨。似乎是因为它与java.lang.System.

(ns entity.system)

(defprotocol System
  ; Protocol methods)
Run Code Online (Sandbox Code Playgroud)

产量

CompilerException java.lang.RuntimeException: Expecting var, but System 被映射到类 java.lang.System,编译:(C:\Users\slomi\IdeaProjects\entity\src\entity\system.clj:3:1)

我尝试System通过添加(:refer-clojure :exclude [System])和来排除(:refer-clojure :exclude [java.lang.System]),但都没有做任何事情;我再次收到同样的错误。

当然,我可以给它起别的名字,但System似乎是最合适的名字,而且类似entity.entity-system/Entity-System甚至entity.system/Entity-System似乎过于多余的名字。

如何java.lang.System从命名空间中排除?

Hoa*_*ael 5

你要找的是 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"
Run Code Online (Sandbox Code Playgroud)