This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-16
Channels
- # beginners (7)
- # boot (63)
- # capetown (1)
- # cider (20)
- # clara (15)
- # cljs-dev (5)
- # clojure (195)
- # clojure-austria (2)
- # clojure-dev (46)
- # clojure-dusseldorf (9)
- # clojure-germany (6)
- # clojure-greece (36)
- # clojure-italy (5)
- # clojure-nl (4)
- # clojure-russia (173)
- # clojure-sg (1)
- # clojure-spec (93)
- # clojure-uk (65)
- # clojure-ukraine (2)
- # clojured (9)
- # clojureremote (1)
- # clojurescript (52)
- # core-async (14)
- # core-logic (5)
- # cursive (21)
- # data-science (8)
- # datomic (60)
- # emacs (83)
- # jobs (9)
- # jobs-discuss (7)
- # juxt (6)
- # klipse (2)
- # leiningen (1)
- # lumo (24)
- # mount (4)
- # numerical-computing (1)
- # off-topic (18)
- # om (37)
- # om-next (5)
- # onyx (13)
- # pedestal (1)
- # perun (44)
- # proton (2)
- # rdf (3)
- # re-frame (24)
- # reagent (4)
- # remote-jobs (3)
- # spacemacs (3)
- # testing (6)
- # vim (10)
- # yada (2)
@gfredericks I’m using test.chuck, but can’t get my head around this. How do I generate two dates - one always smaller than the second?
@ag fmap+sort, such-that+not=
Generate exactly two using tuple or vector
Then fmap and filter that
The filter is to make sure they're not equal
("filter" meaning such-that
)
or generate one date and a quantity and add the quantity to the date
For the record, problem that I had yesterday was actually due to using set (#{}) in :req/:opt for s/keys:
user> (s/exercise (s/keys :req #{:lol/id2} :opt #{:lol/id}))
ExceptionInfo Couldn't satisfy such-that predicate after 100 tries. clojure.core/ex-info (core.clj:4725)
user> (s/exercise (s/keys :req [:lol/id2] :opt [:lol/id]))
([#:lol{:id2 0} #:lol{:id2 0}] [#:lol{:id2 0} #:lol{:id2 0}]…
the s/keys generator also obeys :req and :opt, so generates maps that have only :req keys, which is neat 🙂
another thing, I’m tinkering with generating specs from a source outside code (database schema), and doing something like this:
user> (let [k :lol/id]
(s/def k int?))
user/k
which is not actually what I wanted, so I’m working around it by doing this:
user> (let [k :lol/id]
(eval `(s/def ~k int?)))
:lol/id
Which seems a bit odd. Am I missing something or is the idea that specs are defined firstly in Clojure code and not derived from outside sources?
I faced similar problem when I wanted to generate specs based on an sql db schema by inspection. In that case I generated clojure code.
The macro based API complicates things.
It must be possible to do. I'd love to see examples.
you can do that, or use eval
in the future there may be a lower-level function-based api, however it will not be able to automatically capture forms for explain reporting
lovely idea -> http://dev.clojure.org/jira/browse/CLJ-2112
thumbed that one up, thanks @mpenet. Hacked around that just yesterday to get dynamic conformers “drop extra keys” & “fail on extra keys” working for map specs.
@mpenet has been in the plan from the beginning, but has been blocked behind the various form errors
It would be cool to use s/exercise
to generate a sample structure for documentation, but I would need to tweak a few things: Make all keys required, ensure all collections have >= 1 element.
I'd probably write a function doc-sample
that has the special cases you described, calls itself recursively, and falls back on gen/generate
when it doesn't know what to do
I’m writing a macro that is essentially a wrapper around defn
, so I thought it would be cute to use defn
‘s spec to conform for easy access to the args & body. it works on some, but not when the body of the macro is a map, because..
user> (s/conform :clojure.core.specs/defn-args
'(foo [bar] {:baz 42}))
{:name foo, :bs [:arity-1 {:args {:args [[:sym bar]]}, :prepost {:baz 42}}]}
the body conforms as :prepost
rather than :body
. is there any way to make it backtrack and choose the path where :prepost
is empty and :body
is correct?oh man; does that mean defn
is essentially unspecable?
I mean I guess you could rewrite it with an or
well I don’t think it’s un-specable, just that the conform result does not align with the semantics
that's presumably because the spec is ambiguous
and I don't think it should be
change the spec yourself 🙂
I think it'd be a pretty simple tweaking of this bit here https://github.com/clojure/clojure/blob/c0326d2386dd1227f35f46f1c75a8f87e2e93076/src/clj/clojure/core/specs.clj#L76
you'd wrap the :prepost
and :body
in an or
or alt
or whatever, where the body uses +
instead *
in the branch with the prepost
(s/def ::args+body
(s/cat :args ::arg-list
:rest (s/alt :body+attr (s/cat :prepost (s/? map?)
:body (s/+ any?))
:body (s/* any?))))
user=> (s/conform :clojure.core.specs/defn-args '(foo [bar] {:baz 42}))
{:name foo, :bs [:arity-1 {:args {:args [[:sym bar]]}, :rest [:body+attr {:body [{:baz 42}]}]}]}
user=> (s/conform :clojure.core.specs/defn-args '(foo [bar] {:baz 42} 1))
{:name foo, :bs [:arity-1 {:args {:args [[:sym bar]]}, :rest [:body+attr {:prepost {:baz 42}, :body [1]}]}]}
@bronsa no need for the s/?
at that point, right?
that would go through the second branch
:body+
:body*
:body'
dunno too many names
seems like the spec should be named ::args+prepost+body
and the :rest
is ::prepost+body
aight, I'll make a ticket + patch and just keep it as
(s/def ::args+body
(s/cat :args ::arg-list
:body (s/alt :prepost+body (s/cat :prepost map?
:body (s/+ any?))
:body (s/* any?))))
and rich/alex can figure out some better namingit does?
it looks to me like the only requirement is :pre
's value is a collection
I thought they were arbitrary expressions
have you been using pre-post wrong for years and didn't notice because the functions are always truthy 😄
dynamic languages are a magic surprise
@gfredericks the few slack users that use the slack->irc bridge will know what we've been up to
glad I stopped using that when the threads feature was released
I think it just looked like regular messages
so I would've ended up unknowingly replying to thread messages in the main channel
I can put up with all sorts of nonsense for the sake of technological idealism, but unknowingly looking like a crazy person is not one of them
one thing I really miss about the #clojure irc: slack makes me feel so much more guilty when I derail a conversation/channel into offtopic banter
only because threads exist? or because topics are more specific?