Fork me on GitHub
#clojure-spec
<
2018-08-07
>
scaturr12:08:43

Is there a conventional way to describe a spec as an argument? Like if I have a function that takes a spec? I see s/spec? - but that doesn’t seem to work with something like (s/spec? ::my-spec)

Alex Miller (Clojure team)12:08:39

There is no single predicate for it right now

hmaurer18:08:26

o/. Is there a reason why s/def does not accept an optional docstring?

favila19:08:26

Probably an accident of implementation; A spec is put in a global registry atom, which contains a hashmap from key/symbol to spec objects. There's no clear place to put metadata like there is with vars.

hmaurer19:08:36

@U09R86PA4 isn’t it possible to attach metadata to the keyword representing the spec?

favila19:08:52

you cannot attach metadata to keywords

favila19:08:14

(with-meta :mykw {:abc 123})
ClassCastException clojure.lang.Keyword cannot be cast to clojure.lang.IObj  clojure.core/with-meta--5142 (core.clj:217)

hmaurer19:08:22

it’s really unfortunate; being able to attach doc to specs in this way would be really neat

hmaurer19:08:30

(yep I just tried that :()

favila19:08:51

they could do something, but it wouldn't be the normal var thing

favila19:08:56

that's all

hmaurer19:08:58

especially since the doc function is already able to pull specs from the registry and show the predicate

hmaurer19:08:11

it would be super nice if it could also show an extra description

hmaurer19:08:17

useful in cases where the predicate doesn’t speak for itself

hmaurer19:08:05

I guess the implementation doesn’t really matter; it could be an extra global hashmap from keywords to strings

hmaurer18:08:48

@alexmiller I found this but it hasn’t moved in a while: https://dev.clojure.org/jira/browse/CLJ-1965

Alex Miller (Clojure team)19:08:57

It’s the most voted issue in jira and we are def on board with fixing it

🙌 4
Alex Miller (Clojure team)19:08:36

But there are impl factors meaning it will be a while before it’s implemented