This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-22
Channels
- # arachne (8)
- # bangalore-clj (1)
- # beginners (72)
- # boot (95)
- # braveandtrue (5)
- # business (1)
- # capetown (1)
- # cider (180)
- # cljs-dev (8)
- # cljsrn (20)
- # clojure (104)
- # clojure-art (1)
- # clojure-brasil (8)
- # clojure-czech (1)
- # clojure-greece (15)
- # clojure-korea (13)
- # clojure-poland (2)
- # clojure-russia (53)
- # clojure-sg (5)
- # clojure-spec (60)
- # clojure-uk (35)
- # clojurescript (186)
- # community-development (3)
- # core-async (24)
- # cursive (18)
- # datascript (11)
- # datomic (39)
- # devcards (4)
- # emacs (2)
- # events (1)
- # funcool (23)
- # hoplon (148)
- # juxt (1)
- # ldnclj (2)
- # luminus (1)
- # off-topic (22)
- # om (27)
- # onyx (35)
- # overtone (2)
- # pedestal (7)
- # perun (8)
- # protorepl (2)
- # rdf (6)
- # re-frame (15)
- # reagent (2)
- # ring-swagger (10)
- # untangled (54)
^Thanks for the help. I don’t think I said so properly before as my internet time was up.
Is this anything to be worried about?
(s/conform (s/or) :anything)
=> :clojure.spec/invalid
(s/explain (s/or) :anything)
Success!
=> nil
Here's my experiment in returning only the conformed value of an s/or
spec:
(defmacro meat-grinder-or [& preds]
(let [tags (map keyword
(repeatedly (count preds)
#(gensym "tag")))
prepared (interleave tags preds)]
`(s/and (s/or ~@prepared)
(s/conformer val))))
On the first question, that doesn't seem right, agreed. Feel free to log it if you like
@alexmiller What do you mean by log it?
No, sorry (it's on the list)
Is there an easy way to get the keys of a map spec pulled from the registry? I feel like there must be an obvious way I'm overlooking. I can just generate one & get the keys from that, but that feels inelegant (& might be incomplete if it had optional keys).
you can use s/form to get the form version of it
when we release form specs, you could then conform with that to extract the keys
but you can work around that for the time being
Excellent. Thanks @alexmiller!
That's actually going to be broadly useful for me; I had overlooked s/form until now.
there are a number of remaining issues with it and I have patches for most of those in the queue
in particular all of the coll specs and keys* have broken forms atm
and maybe conformer (can’t remember if that’s been applied yet)
those will all be fixed
Is there something I can read to better understand query caching and how to optimize queries?
@zane Could you elaborate? That doesn’t sound related to clojure.spec...
Thanks for taking my question seriously anyway, @seancorfield. 😉
@zane Ah, I wondered if it was for JDBC in which case I’d be happy to field it… in #clojure 🙂
Does anyone have any tips on using clojure.spec to validate some data conforms to the spec in a clojure.test? Obviously I can do (is (s/valid? ::spec data)
but if its invalid I want to see the explain output…
we were waiting for you to do it
Just a quick bit of feedback. This is a circular dependency thing. I generated some specs based on my relational database schema tables became (s/keys ...) fields became simple (s/def :schem.table/field pred) one-to-many relations became (s/def :schem.table/rel (s/coll-of :schem/table)) many-to-one relations became (s/def :schem.table/rel :schem/table)
The slightly fiddly bit was the relations
I couldn't dump these all in one file because the table specs needed to exist before the relation specs could be processed. (more specifically order mattered or it would throw an error)
I was hoping all (s/def ...) statements were essentially lazy but perhaps that's not the case for performance reasons.
I might need to produce a simple example to demonstrate this.
(s/def ::a ::b)
throws
CompilerException java.lang.Exception: Unable to resolve spec: :example.order-matters/b, compiling:(order_matters.clj:11:1)
My work around is to do all table defs first since they reflect relations. s/keys
doesn't require the req/opt specs exist before the s/def
@alexmiller: presumably the right thing to do is to extend assert-expr
to operate on something like 'valid?
@olivergeorge I believe you can avoid that by doing (s/spec ::b)
Thanks @bfabry I did wonder if there might be something like that. I'll experiment more.
No worries.
Actually this works: (s/def ::a (s/and ::b))
I wonder if there's a concise definition of which spec macros require definition and which don't
Not sure I'd say neat exactly but it'll do the trick in my case.
I'd be interested in hearing from @alexmiller if this is technically a bug or if "declare before use" is an implementation requirement/assumption
@bfabry thanks for the inspiration 🙂
I'd say bug, file a jira
Everything should have delays, but there are a few places missing them
Thanks Alex. Will do.
That's either really easy to fix or really hard :)
Logged. Please tell me if it's not a well formed JIRA ticket. http://dev.clojure.org/jira/browse/CLJ-2067
eventually @alexmiller will release a spec for jira tickets so you'll be able to s/valid? them before submitting them
what do people think of this clojure.test extension for spec?
(defmethod assert-expr 's/valid? [msg form]
(let [spec (second form)
input-val (nth form 2)]
`(let [value# ~form]
(if value#
(do-report {:type :pass, :message ~msg,
:expected '~form, :actual value#})
(do-report {:type :fail, :message ~msg,
:expected (:clojure.spec/problems (s/explain-data ~spec ~input-val)), :actual ~input-val}))
value#)))
Output looks like this:
FAIL in (foo-test) (common.clj:18)
expected: [{:path [],
:pred (* :user/foo),
:val "1",
:via [:user/foo],
:in []}]
actual: "1"
@olivergeorge good enough, I’ll tweak as needed
Thanks Alex