Fork me on GitHub
#clojure-spec
<
2016-09-09
>
Alex Miller (Clojure team)13:09:27

The validation benchmark has been updated with alpha12 showing the spec improvements: http://muhuk.github.io/validation-benchmark

ghadi14:09:57

Pretty massive improvements

Alex Miller (Clojure team)14:09:32

yes, should help a lot with runtime use cases

otfrom15:09:08

alexmiller: that's great. Means I'll use it to conform stuff in my sparkling spark jobs. :-D Thx!

Alex Miller (Clojure team)15:09:45

generally, it’s faster than schema, so if schema was fast enough for you, it should be sufficient

otfrom15:09:05

alexmiller: that was my alternative so I'm very happy. :-D

seancorfield15:09:55

I'm going to have to study the commit(s) that are responsible for that massive speed up -- very curious about how that was achieved! 😸

Alex Miller (Clojure team)15:09:11

lot of changes. one change of possible importance is that a spec using another registered spec will “compile” in that definition, so changes to the upstream spec (during dev) now require the downstream spec to be reloaded

Alex Miller (Clojure team)15:09:20

so it’s a little less dynamic than prior

Alex Miller (Clojure team)15:09:37

this does not affect recursive specs as delays are used

otfrom15:09:50

> (s/conform (s/coll-of int? :type set?) #{0 1})
#{0 1}
> (s/conform (s/coll-of int? :type set?) [0 1])
[0 1]
(s/conform (s/coll-of int? :type set?) [0 "e"])
:clojure.spec/invalid

otfrom15:09:02

not sure why I'm not getting invalid on the 2nd one

otfrom15:09:57

ah, I think I need :into

otfrom15:09:12

> (s/conform (s/coll-of int? :into #{}) [0 1])
#{0 1}

otfrom15:09:21

seems to work

jannis15:09:30

I'm hitting odd behavior with clojure.spec and I'm not sure it's me or a bug in clojure.spec. Here's the example: https://gist.github.com/Jannis/f23a2ecf350b401745d190b02bbb619c What I would expect is no surrounding [] around [:nested ...] in the second case. It seems that ::link-value spec is clashing with the ::query spec. If I change ::link-value to e.g. (s/tuple symbol? keyword?) I don't get the extract []. The odd thing is that despite the "clash", [:link ...] never appears in the output... any ideas?

Alex Miller (Clojure team)16:09:39

if only you had the spec specs, it would tell you that :)

Alex Miller (Clojure team)16:09:24

@jannis so the one you’re asking about is

(s/conform ::query '[a b [c d]])
;;=> [[:single [:simple a]]
;;    [:nested {:parent [:simple b], :children [[:single [:simple c]]]}]]

Alex Miller (Clojure team)16:09:53

the outermost [ ] is from ::query

Alex Miller (Clojure team)16:09:10

the [ ] around :single and :nested are due to the s/alt tagging

otfrom16:09:26

@alexmiller thx. Mostly just flailing around in the library trying to learn it (and getting dumb things wrong) 😉

jannis16:09:53

@alexmiller The one I'm asking about is [[:single [:simple a]] [[:nested ...]]] - with the [[:nested ..]] instead of [:nested ..].

jannis16:09:00

What's puzzling me there is that the other two examples don't have the extra [] around [:nested ...] - and that I can make it disappear in the second case if I change the :link-value spec that should have no impact here.

jannis16:09:35

(This is Clojure 1.9.0-alpha11 by the way)

Alex Miller (Clojure team)16:09:20

oh, this reminds me of something

Alex Miller (Clojure team)16:09:39

that example in the comment also has something similar

Alex Miller (Clojure team)16:09:12

I’ve been looking at some regex conform results that seem off to me - although most of those relate to use of s/?

jannis16:09:12

The output certainly looks similar 😉

jannis16:09:13

In this case I think s/conform may not know which of [::query :single :link] and [::query :nested :children] to pick. It decides on :nested instead of :single but surrounds it with the extra [] for some reason.

jannis16:09:23

Could that be what happens in case of ambiguity?

Alex Miller (Clojure team)16:09:37

I don’t think that’s what’s happening - I think it has to do with the guts of the regex derivatives and when it decides to create the nested context

jannis16:09:37

You know the internals, I don't. 😉 Is there anything I can do to help investigate the problem (if it is one at all)?

Alex Miller (Clojure team)17:09:06

no, I’m looking at some of this stuff already

Alex Miller (Clojure team)17:09:23

if you wanted to boil it down to a simpler repro and file a jira, that would be helpful

Alex Miller (Clojure team)17:09:42

just to make sure that it does get addressed and not just “in my head” :)

fenton20:09:55

how do I spec that a map should look like: {:db/id <something>}. I don't own the db namespace so am not sure how to spec for that.

bfabry20:09:39

@fenton you don't need to own a namespace to refer to it

Alex Miller (Clojure team)20:09:58

and then separately (s/def :db/id <something>)

Alex Miller (Clojure team)20:09:40

which could come from a lib or could be something you build

fenton20:09:20

(s/def :db/id (s/tuple #{:pc.api/name} string?)) (s/def ::kwm (s/keys req [:db/id]))

fenton21:09:01

{:db/id [:pc.api/name "JCZ4vAlwyUl6r37PeVJ"]} is what i'm going for

fenton21:09:23

repl> (gen/generate (s/gen :pc.api/kwm)) {}

fenton21:09:36

pcbe.http> (s/valid? :pc.api/kwm {:db/id [:pc.api/name "orange"]}) true