I'm writing a Entity Component System. Part of my plan is to have a protocol called System that a system must fulfill to use the ECS.
The problem is, Clojure complains if I try to create a protocol called System; seemingly because it clashes with java.lang.System.
(ns entity.system)
(defprotocol System
; Protocol methods)
yields
CompilerException java.lang.RuntimeException: Expecting var, but System is mapped to class java.lang.System, compiling:(C:\Users\slomi\IdeaProjects\entity\src\entity\system.clj:3:1)
I tried excluding System by adding both (:refer-clojure :exclude [System]) and (:refer-clojure :exclude [java.lang.System]), but neither did anything; I received the same error again.
Of course I could just name it something else, but System seems the most appropriate name, and something like entity.entity-system/Entity-System or even entity.system/Entity-System seems overly redundant.
How can I exclude java.lang.System from the namespace?
What you're looking for is 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With