Fork me on GitHub
#clojure-spec
<
2017-12-02
>
gklijs11:12:01

I had an issue with a spec I defined in a .cljc file. I use an or to make one of two keys required. That’s working fine. But when I inspect the form in clj the or is without namespace, while I was expecting the namespace to be clojure.core.

Alex Miller (Clojure team)13:12:41

What do you mean by “inspect”?

gklijs14:12:05

I debugged by adding logging. (namespace x) is empty in the .cljc one, but clojure.core when the spec is defined in a .clj file.

Alex Miller (Clojure team)15:12:07

I still don’t understand a) what you’re doing b) what you’re seeing or c) what you expect to see

gklijs16:12:00

What I do is have a library which for a subset of what’s possible to spec, transform the namespaced data into a vector without namespaces in such a way that I’m able to get back to namespaced map from the vector. Part of this is checking the form of the spec used. When you use clojure.spec.alpha/keys, you can use clojure.core/or to be able to spec “one of these should be there”. Now when the spec id defined in a .clj file the or is namespaces eith clojure.core, but when the spec is defined in a .cljc file the or has no namespace. I now solved it by looking only at the name of the or symbol. So there is no real problem anymore, but I was surprised this was happening.