Fork me on GitHub
#clojure-spec
<
2019-02-05
>
Vincent Cantin09:02:39

Where do clojurists usually place their fdef? - In the same namespace of their functions? - In the same namespace with “.spec” prepended? - In a separate, global /src/spec/ namespace tree? - other?

n2o11:02:04

I usually put it directly below the function definition, but i am not really happy with it to be honest.

Vincent Cantin11:02:23

Why aren’t you fully satisfied with it?

n2o12:02:22

the source code feels a bit messy. Simple clean functions, then a new definition below it just for specs... Just a personal impression. Some kind of choppy in my opinion

n2o12:02:06

I tried to put them into a separate namespace but as you have to instrument them to really use the specs, the specs are like to be forgotten. So this does not seem to be a good solution

n2o12:02:48

I then tried to put them below my source code, but in the same namespace (at the bottom of the file). I almost forgot all of them and was wondering, that I wrote specs for those functions when I scrolled down the file after some months. So this is also not a good solution

n2o12:02:23

Currently I put them directly together, so I don't forget them

(defn foo [x y] ,,,)
(s/fdef foo
  :args (s/cat :x number? :y pos-int?)) 

seancorfield17:02:11

If I want the code to be usable without spec (i.e., on Clojure 1.8), I put fdefs in a separate namespace (see clojure.java.jdbc for example). Otherwise I put the fdef immediately above the function it refers to.

n2o09:02:53

Ok, in my case I do not need to be downwards-compatible. But yes, then you don't have a different choice.

borkdude09:02:11

@vincent.cantin The answer is: up to you. There is no “best way” regarding this. Personally, I co-locate it with the defn.

abdullahibra13:02:19

how could i check the values of map only using clojure.spec, i know how can i do this for map keys names + values, but i'm in situation which i don't know what key names are but i know what types of values should be ?

borkdude13:02:52

e.g. for checking string values: (s/map-of any? string?)

abdullahibra13:02:56

should handle the values using s/coll-of

abdullahibra13:02:25

is clojure.spec good alternative to type system in language like Haskell, ocaml ?

hmaurer20:02:27

most definitely not

hmaurer20:02:48

it’s very different and by no mean a substitute for static typing (as much as I like spec)

borkdude13:02:48

it has different applications, everything’s runtime, so you get no compile time guarantees, macros being the exception

borkdude13:02:07

but it’s also more flexible than a type system. different trade offs.

manutter5114:02:38

Also spec is still evolving, there are going to be changes, especially concerning how maps are spec’ed.

borkdude14:02:08

would it make sense to co-develop the CLJS version of spec2 in the same repo and pull it outside CLJS itself, so CLJS never is behind on spec?

borkdude14:02:21

like test.check

borkdude14:02:12

am I right that you can’t use anonymous functions in specs anymore in spec2 so they would always have to be defined top-level? what about with-gen?

borkdude14:02:48

thanks for the link @victorbjelkholm429, useful information

Alex Miller (Clojure team)14:02:22

I do not think you should be tracking spec 2 changes in cljs yet - still in flux

Alex Miller (Clojure team)14:02:07

you can use anonymous functions

borkdude14:02:24

I’m reading about “symbolic specs”, it seems that you cannot use anonymous functions in there?

borkdude14:02:50

Symbolic specs consist only of:

Spec forms (lists/seqs), with spec op in function position, composed of other symbolic specs
Qualified keywords (names that can be looked up in the registry)
Qualified symbols (predicate function references)
Sets of constant values (an enumeration)

Alex Miller (Clojure team)14:02:35

so those are valid spec forms

borkdude14:02:52

ah ok. I was confused, because of feedback you had earlier, I thought it wasn’t allowed anymore, but then I misunderstood

taylor19:02:04

I really like the music notes at the end of each post! There's some good lesser-known stuff on Zeppelin's In Through the Out Door too 🙂 are you a fan of The Meters?

Alex Miller (Clojure team)19:02:35

been listening to the first Meters album a lot lately actually :)

👏 5
🎺 5
Alex Miller (Clojure team)14:02:56

it has a note about fn in the middle there

Alex Miller (Clojure team)14:02:41

if you want to use anonymous functions at the top level with the api functions, you need to wrap them in s/spec

borkdude14:02:13

alright. I don’t know how much in flux things are, but if you want me to give it a try again with speculative, let me know.

Alex Miller (Clojure team)14:02:51

(s/valid? (s/spec #(> % 5)) 10)

Alex Miller (Clojure team)14:02:28

I’ve got at least one thing to fix still from Sean’s feedback

Alex Miller (Clojure team)14:02:52

and we’re working through best direction for some of the things you saw last time still

Alex Miller (Clojure team)14:02:14

so probably not worth doing anything yet

drone23:02:43

maybe using spec in an unintended way, but I ran into a situation where there were two spec forms in an s/and, the result of the first conformed the input and the second spec form in the s/and was a predicate expecting the original input, not the modified/conformed form. it feels like validation should be independent of conforming

drone23:02:56

and I don’t understand the purpose of conforming. is it intended to be like schema’s coercion? or is it to produce some intermediate form useful for spec-checking?

Alex Miller (Clojure team)23:02:44

Re and, we have long considered having both “flowing” and nonflowing variants of and

Alex Miller (Clojure team)23:02:54

And that might still happen in spec 2

Alex Miller (Clojure team)23:02:41

The purpose of confirming is not coercion - it’s to tell you which choices were made during validation for optional specs or components

Alex Miller (Clojure team)23:02:10

That is, why was it valid?

drone23:02:14

Sounds good. The flowing was definitely surprising.

drone23:02:28

Thanks, got it

drone23:02:39

A lot of design decisions