Fork me on GitHub
#clojure-spec
<
2018-06-08
>
martinklepsch17:06:47

Is there a way to find out from what namespace/file a spec has been defined?

seancorfield19:06:42

I'd be very interested in hearing an answer to this too!

bmaddy17:06:18

Here's a spec puzzle for someone. I'm trying to get a spec that defines something like this:

([-7806 "rBQUP"] :_T-7/G0X)
I thought I would need to nest calls to s/cat to do it, but those seem to flatten or something:
> (gen/generate (s/gen (s/cat :int int? :str string?)))
(-61568 "66420tRep6jHRW6q07x647hV6qE6q")
> (gen/generate (s/gen (s/cat :pair (s/cat :int int? :str string?) :keyword keyword?)))
(-7806 "rBQUP" :_T-7/G0X)
How do I get a collection of two items, where the first is a collection of one int and one string, and the second is a keyword?

taylor18:06:48

like hiredman said below, this should work: (gen/generate (s/gen (s/cat :pair (s/spec (s/cat :int int? :str string?)) :keyword keyword?))) just to prevent the "flattening" of the nested regex specs

djtango08:06:39

late to the party, s/tuple isn't a regex spec so you can nest it as you like:

(s/valid? (s/tuple (s/tuple int? int?) keyword?) [[1 2] :a])

hiredman18:06:01

wrap (s/spec ...) around the inner cat I think

hiredman18:06:01

nested regex specs sort of collapse into a single regex spec (nested cats become subsequences within the outer sequence) so you have to insert something to tell spec where to stop collapsing them, and I think it is wrapping with s/spec, but it has been a while

☝️ 8
bmaddy19:06:55

That worked! Thanks @hiredman and @taylor! 😄

👍 4
seancorfield19:06:42

I'd be very interested in hearing an answer to this too!