This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-05
Channels
- # adventofcode (8)
- # aleph (42)
- # announcements (4)
- # beginners (157)
- # boot (4)
- # calva (1)
- # cider (6)
- # cljdoc (8)
- # cljs-dev (1)
- # cljsrn (3)
- # clojure (50)
- # clojure-europe (9)
- # clojure-italy (16)
- # clojure-nl (2)
- # clojure-russia (6)
- # clojure-spec (59)
- # clojure-uk (25)
- # clojurescript (20)
- # core-async (41)
- # cursive (30)
- # data-science (9)
- # datomic (20)
- # fulcro (28)
- # kaocha (9)
- # nrepl (1)
- # off-topic (3)
- # om (3)
- # pathom (10)
- # re-frame (8)
- # reagent (2)
- # ring-swagger (38)
- # rum (9)
- # shadow-cljs (209)
- # spacemacs (7)
- # tools-deps (11)
- # vim (6)
- # yada (2)
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?
I usually put it directly below the function definition, but i am not really happy with it to be honest.
Why aren’t you fully satisfied with it?
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
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
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
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?))
If I want the code to be usable without spec (i.e., on Clojure 1.8), I put fdef
s in a separate namespace (see clojure.java.jdbc
for example). Otherwise I put the fdef
immediately above the function it refers to.
Ok, in my case I do not need to be downwards-compatible. But yes, then you don't have a different choice.
@vincent.cantin The answer is: up to you. There is no “best way” regarding this. Personally, I co-locate it with the defn
.
Hello guys
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 ?
should handle the values using s/coll-of
ah great
is clojure.spec good alternative to type system in language like Haskell, ocaml ?
it’s very different and by no mean a substitute for static typing (as much as I like spec)
it has different applications, everything’s runtime, so you get no compile time guarantees, macros being the exception
Also spec is still evolving, there are going to be changes, especially concerning how maps are spec’ed.
for more details about the changes: https://github.com/clojure/spec-alpha2/wiki/Differences-from-spec.alpha
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?
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?
thanks for the link @victorbjelkholm429, useful information
I do not think you should be tracking spec 2 changes in cljs yet - still in flux
you can use anonymous functions
what about with-gen?
I’m reading about “symbolic specs”, it seems that you cannot use anonymous functions in there?
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)
spec op can be fn
so those are valid spec forms
ah ok. I was confused, because of feedback you had earlier, I thought it wasn’t allowed anymore, but then I misunderstood
there’s a picture at http://insideclojure.org/2019/02/02/journal/ if that helps
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?
yep and yep
been listening to the first Meters album a lot lately actually :)
it has a note about fn in the middle there
if you want to use anonymous functions at the top level with the api functions, you need to wrap them in s/spec
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.
(s/valid? (s/spec #(> % 5)) 10)
I’ve got at least one thing to fix still from Sean’s feedback
and we’re working through best direction for some of the things you saw last time still
so probably not worth doing anything yet
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
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?
Re and, we have long considered having both “flowing” and nonflowing variants of and
And that might still happen in spec 2
The purpose of confirming is not coercion - it’s to tell you which choices were made during validation for optional specs or components
That is, why was it valid?