This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-15
Channels
- # admin-announcements (3)
- # architecture (2)
- # beginners (54)
- # boot (85)
- # braveandtrue (8)
- # cider (21)
- # cljs-dev (56)
- # cljs-site (5)
- # cljsjs (15)
- # cljsrn (9)
- # clojars (4)
- # clojure (99)
- # clojure-austin (1)
- # clojure-russia (36)
- # clojure-spec (53)
- # clojure-uk (29)
- # clojurescript (161)
- # datomic (8)
- # hoplon (3)
- # immutant (48)
- # jobs (1)
- # jobs-rus (1)
- # leiningen (10)
- # om (23)
- # om-next (1)
- # onyx (22)
- # parinfer (3)
- # planck (13)
- # protorepl (8)
- # re-frame (46)
- # reagent (2)
- # remote-jobs (1)
- # respo (1)
- # specter (5)
- # testing (12)
- # untangled (50)
- # yada (13)
Reminder: https://github.com/gfredericks/schpec exists and you might like it and it could use some eyeballs 🙂
I’ll probably end up contributing regex-str spec at some point because I gotta write it anyway
Would re-matches
and re-find
be weird?
I wonder how I’d write the generator for has-re?
or whatever; so far I only care about the entire re
I guess I could generate prefix string, re string, suffix string in parallel and then fmap str/join
Perhaps this is obvious but I just noticed that cljs.spec doesn’t seem to define an assert macro a la clojure.spec
If I want to always validate a function's input against an fdef spec, do I need to use the clojure.spec.test namespace? Or does the namespacing suggest that eg. clojure.spec.test/instrument is only for use in development and tests and I shouldn't use it otherwise?
@brabster: Maybe you can separate out the args spec and refer to it in the fdef - and then call s/valid? in your function (or hook it up with :pre)?
@borkdude: you're right, I did that but it's quite a lot of extra typing if the individual arg specs aren't really reusable anywhere - and when I use a spec in a precondition the error message doesn't give any details of why the validation failed (just gives the name of the spec)
plus I seem to frequently end up with what feels like duplication like (s/cat :foo ::foo :bar ::bar :baz ::baz)
when I break the specs out - maybe i'm just writing bad clojure or something 🙂
(tbh I'm struggling a little to work out when/when not to use namespaced keywords too :P)
It's quite annoying to get the arguments as a vector that you can validate yourself, isn't it?
Say we have:
(s/def ::my-fn-args (s/cat :n number? :s string?))
(s/fdef my-fn :args ::my-fn-args)
(defn my-fn [n s] (if (s/valid? ;; now what?
What I'm also a bit uneasy with is that you have to repeat the argument names and that there's a possible source of duplication error.
I imagine there are plans to integrate spec more deeply with core stuff like defn so maybe this is a bit painful because it's early days
It would be cool if you could write a spec and then the function using the spec:
(defn my-fn ::my-fn-args ...)
Kind of like that.With the option to disable at runtime if you want to trade off the safety for slightly faster code
What might be even nicer is combined spec conform and destructuring if that's possible
Thanks for the input @borkdude, more confident I'm not missing something really obvious now 🙂
@brabster: No problem, I'm also just beginning to see the dimension that spec adds to Clojure. Pretty excited about it.
@borkdude: seems really useful ... maybe it should do the conform so you specify something like (defn my-fn [{:keys [destructuring form]} ::my-fn-args] ...) and you could get the destructured pieces in your arguments?
(defn my-fn #[n number? :s string?] ...)
without having to destructure
vs
(defn my-fn [{:keys ....]] (s/cat :n number? :s string?) ...)
you can call s/form and grab the odd elements
(->> (s/cat :a string? :b keyword?) s/form (drop 1) (partition-all 2) (map first))
spectrum.conform/parse-spec returns defrecords for the vast majority of specs. 100% coverage is a goal
Having an error specing a function that takes a seq of maps. Here’s a gist with a cljc and error. https://gist.github.com/mmb90/e2e33cb526ed8c25549edbdb6e48f711
It seems to think it should be getting a map instead of a seq of maps. Is there a detail I’m missing?
@mmb90: s/*
is a regex for zero or more of these specs — so you’re saying name-unicorns
takes zero or more arguments, each of which should match the ::unicorn
spec.
I think you want s/coll-of
for a collection of ::unicorn
entities.
@seancorfield: The s/* is inside of an s/cat pulling out the first argument, so I thought the spec said that name-unicorns takes one argument which is a sequence of zero or more ::unicorns entities.
The s/cat
is for the entire :args
sequence.
In s/fdef
you specify :args
as a sequence — as if you always invoked the function with apply
.