I am able to register a spec with an unresolvable symbol even though the docs seem to indicate this should not be an acceptable value for the registry. Is this safe? Will it keep working?
The documentation for s/def
says it takes as its first argument "a namespace-qualified keyword or resolvable symbol." This is more expansive than the spec Guide, which says, "Spec names are always fully-qualified keywords."
But I recently switched a bunch of specs from keywords to symbols (fully qualified but unbound) and everything seems to work fine, from s/valid?
to s/conform
to s/assert
, referencing the definitions in s/keys
, etc.
Here is a reduced example:
user> (require '[clojure.spec.alpha :as s])
nil
user> (ns-resolve 'com.example 'foo)
Execution error at user/eval30383 (form-init8866507034262802929.clj:53).
No namespace: com.example found
user> (s/def com.example/foo string?)
com.example/foo
user> (s/valid? 'com.example/foo "x")
true
user> (s/valid? 'com.example/foo 42)
false
user> (s/valid? (s/keys :req ['com.example/foo]) {'com.example/foo "x"})
true
user> (ns-resolve 'com.example 'foo)
Execution error at user/eval30389 (form-init8866507034262802929.clj:62).
No namespace: com.example found
user>
I am guessing this is an instance where the implementation has raced a bit ahead of the docs, and even further ahead of the guide. Either or that or maybe I'm misunderstanding what "resolvable symbol" means. Thanks for any guidance or tips!