This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-25
Channels
- # admin-announcements (3)
- # alda (2)
- # beginners (10)
- # boot (44)
- # cider (31)
- # cljs-dev (5)
- # cljsjs (2)
- # cljsrn (17)
- # clojure (181)
- # clojure-austin (2)
- # clojure-brasil (18)
- # clojure-canada (1)
- # clojure-conj (5)
- # clojure-dev (11)
- # clojure-gamedev (30)
- # clojure-russia (380)
- # clojure-spec (50)
- # clojure-uk (35)
- # clojurescript (146)
- # clojutre (1)
- # component (1)
- # cursive (62)
- # datomic (27)
- # dirac (7)
- # editors (23)
- # emacs (7)
- # events (34)
- # funcool (22)
- # hoplon (134)
- # jobs (22)
- # jobs-rus (7)
- # juxt (1)
- # kekkonen (1)
- # lein-figwheel (54)
- # leiningen (7)
- # luminus (2)
- # off-topic (5)
- # om (4)
- # onyx (27)
- # proton (5)
- # protorepl (2)
- # re-frame (16)
- # reagent (29)
- # rethinkdb (2)
- # schema (1)
- # untangled (61)
- # yada (9)
Hi all, i think this question already was answered, but - how to restrict collection of keys in map, i.e. no extra keys?
I assume there isn’t a standard way of doing it to be liberal in what you should be able to receive as data
I've already read this thread - https://clojurians-log.clojureverse.org/clojure-spec/2016-06-09.html 🙂 We want to use clojure.spec instead of json schema and we have many cases of miss-typed keys, so validating this would be helpful. :closed true
would be nice, but let's start from custom pred.
Then another question: s/and report errors of first failed predicate, could i compose two predicates - so both be applied, even if first failed?
There is a excl-keys in https://github.com/gfredericks/schpec
(defn keys-diff [expected provided]
(let [expected (set expected)
provided (set provided)
missing (set/difference expected provided)
extra (set/difference provided expected)]
{:missing-keys missing
:extra-keys extra}))
thx @minimal , i've got it. It's not problem to write extra-keys predicate, but force validation and reporting both extra-keys and s/keys
At one point someone here was trying to convert spec
s to BNF grammars - what came of that?
That could be incredibly valuable - it would be very useful if you could compile a spec
into a .proto
file, or even C++ code for a JNI interface.
Has anyone had experience setting up clojure.spec.test/check
to run automatically (e.g. via lein test
)?
I know you can wrap it in a (deftest foo (testing ...))
, but the output of an is
failure isn't as verbose as the output of check
.
@potetm I use something like this (might need to be updated for latest alpha): https://gist.github.com/alexanderkiel/931387c7a86c1879b2267ad064067af7
Are there any examples of non-trivial uses of instrument
, esp. showing how :spec
, :stub
, :gen
, and :replace
are used?
Yes, I have, and it has been really useful. It’s just we’re trying to figure out how to use instrument and check together for some functions that may not be specced or only partially specced.
The videos on ClojureTV have also been useful, but a more thorough example that shows how to use some of the arguments to instrument to deal with things that might otherwise be considered part of a “test fixture”.
http://clojure.org/guides/spec#_combining_code_check_code_and_code_instrument_code has one example and I will write a blog on it eventually (but prob not for a while)
I think Stu might have a screencast in mind for it, but not sure
I've been getting this exception a lot lately when running check
: "Additional data must be non-nil." Any thoughts on why?
that shouldn’t ever happen :)
it basically means that conform failed, but explain didn’t find any problems so ex-info was created with a nil map
unfortunately this exception happens while throwing the useful exception so it’s hard to diagnose
but it’s definitely a bug whatever it is
a bug in Clojure that is
and if you can figure out what it is, I’d love a jira on it
it’s not too hard to hack Clojure itself to dump more info when this happens if you have the interest in doing so
FYI, I’m doing a half day spec workshop at the Conj this year - tickets available now https://ti.to/cognitect/clojure-conj-2016
If I can come up with a consistent minimal repo, I'll file a ticket.
I'm going to venture a guess, though, based on some recent debugging, which is that it seems to occur when I have a function that returns another spec'ed function, and the returned function throws an exception while spec is checking it. Just a guess, will try to see if that stick consistently when I have a little time.
hmm, well I guess that’s possible too (although I’d put that one on you :)
Apache library 😞
ok, I’ll put it on Apache :)
@alexmiller: Any expectation of previous spec knowledge for your Conj workshop, or can we come in blind?
I will expect basic Clojure knowledge :)
Perfect, I should be able to handle that 🙂
This might be a stupid question, but can anyone give me a hint how to spec the following function:
(defn my-apply [f & args]
(apply f args))
(This is a simplified version of what I actually have.)
My problem is in expressing that (count args)
has to be equal to the number of parameters that f
takes...