Fork me on GitHub
Ben Lieberman17:02:35

question about resolving specs: is there a way to require a spec out of the global registry as if it were a regular var in a ns? I have discovered that I can't do something like (require [ :refer [baz]]) presumably because baz is not interned in the ns but is instead in the registry? Is that correct?

Alex Miller (Clojure team)18:02:37

correct, specs are not vars

Alex Miller (Clojure team)18:02:15

you could put a spec in a var with (def my-spec (s/get-spec ::foo)) if you wanted to for some reason

Ben Lieberman18:02:28

no, not necessary, I'm fine with it being in the registry. So if require the whole ns say as fspec and then resolve ::fspec/baz its just looking in the registry for that fully qualified name?

Ben Lieberman18:02:16

that's how I have been doing it at any rate

Alex Miller (Clojure team)18:02:40

not sure I understand "require the whole ns say as fspec " but fspecs are also just specs in the registry (but their keys are fully-qualified symbols, not keywords)

Alex Miller (Clojure team)18:02:25

s/fdef just creates a spec with s/fspec, then adds it to the registry (which is just a map) with the fq symbol as the key

Ben Lieberman18:02:31

sorry, that was a poor choice of alias on my part

Ben Lieberman18:02:47

I am not talking about function specs, just any spec in general

Alex Miller (Clojure team)18:02:07

then yes, that is how it works


@U03QBKTVA0N Don't forget there's :as-alias now in a require so you can create an alias for resolving Spec names without having to actually load a real namespace.


(ns using.specs
  (:require [ :as-alias idne]))

::idne/bar ;=>
and no i/do_not/exist.clj file is needed for this.

Ben Lieberman23:02:56

oh thanks @U04V70XH6 I did not know about as-alias. That's helpful.