Fork me on GitHub
#clojure-spec
<
2018-04-23
>
steveb8n05:04:46

I have a problem with a recursive spec in a cljc file. it’s the ::tree (and ::node) spec here https://github.com/stevebuik/Stu/blob/master/src/cljc/viz/core.cljc

steveb8n05:04:22

works fine within this project but when invoked via an installed dep in another project, this spec fails to load

steveb8n05:04:32

anyone seen anything like this before?

steveb8n05:04:44

I’ve tried using (s/spec (s/* ::node)) but no change in behaviour

thomas15:04:16

silly question.. but how do I spec a string which has to have a certain value?

taylor15:04:32

you can use a set as a predicate

thomas15:04:32

something like this: (s/def :mqtt/protocol-name "MQTT") but that doesn't quite work

thomas15:04:42

at least not for the generators.

taylor15:04:55

(s/def ::my-spec #{"MQTT"})

thomas15:04:39

thank you, that did the trick of course!

👏 4
kkruit17:04:22

Is there a way to compare the :pred response from s/problem to the s/def record?

kkruit17:04:46

i'm trying (=(:pred (first (s/problem issue))) :test.spec/equal?)

kkruit17:04:09

when i debug the value of pred is the value of the s/def

kkruit17:04:34

but i'm getting false

kkruit17:04:21

something like that

kkruit17:04:19

is there a way to compare functions like that?

kkruit17:04:59

oh, nevermind, it's in :via, thanks 😅

richiardiandrea19:04:39

I have never noticed this, but basically the output of clojure spec does not expand nested specs:

user=> (doc my-ns.core/test-fn)
-------------------------
my-ns.core/test-fn
([n])
Spec
  args: (cat :n :test-ns)
  ret: any?
nil
Is there a way to see what the :test-ns spec actually is?

Alex Miller (Clojure team)19:04:37

you can invoke doc on spec names too

Alex Miller (Clojure team)19:04:54

I would expect that to be a qualified keyword above though

Alex Miller (Clojure team)19:04:05

not sure if you altered the output

Alex Miller (Clojure team)19:04:43

user=> (doc :clojure.core.specs.alpha/args+body)
-------------------------
:clojure.core.specs.alpha/args+body
Spec
  (cat :args :clojure.core.specs.alpha/arg-list :body (alt :prepost+body (cat :prepost map? :body (+ any?)) :body (* any?)))

richiardiandrea19:04:57

do I need to namespace it? I have a global :test-ns only

Alex Miller (Clojure team)19:04:27

spec names are expected to be namespaced

Alex Miller (Clojure team)19:04:48

maybe we’re talking about different things

Alex Miller (Clojure team)19:04:01

spec names should be qualified, as in :foo/bar

richiardiandrea19:04:19

no you are right my bad

richiardiandrea19:04:28

perfect thanks it works fine 😉