This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-15
Channels
- # announcements (11)
- # beginners (66)
- # boot (6)
- # clara (25)
- # cljdoc (4)
- # cljs-dev (22)
- # clojure (261)
- # clojure-dev (1)
- # clojure-europe (2)
- # clojure-italy (15)
- # clojure-losangeles (1)
- # clojure-nl (19)
- # clojure-spec (62)
- # clojure-uk (50)
- # clojurescript (12)
- # community-development (6)
- # cursive (60)
- # datomic (21)
- # emacs (2)
- # figwheel (2)
- # figwheel-main (3)
- # fulcro (2)
- # graphql (11)
- # hyperfiddle (11)
- # javascript (1)
- # jobs (6)
- # juxt (1)
- # kaocha (5)
- # keechma (2)
- # off-topic (4)
- # onyx (10)
- # pathom (7)
- # re-frame (15)
- # reagent (8)
- # remote-jobs (2)
- # ring-swagger (14)
- # shadow-cljs (35)
- # sql (22)
- # testing (9)
- # tools-deps (62)
- # vim (12)
How can I create a generator that either generates something of a type or nil? (e.g. (spec/gen (spec/inst-in start end))
or nil
)
prolly lower too, but we ran on 1.8 + clojure-future-spec smoothly for a while on some services
Hi all, Where can I start to learn spec?
https://clojure.github.io/spec.alpha/clojure.spec.gen.alpha-api.html#clojure.spec.gen.alpha/fmap
hi one of my devs is playing with spec, and ran into this issue when composing a couple
(s/def ::even-or-odd (s/or
:even even?
:odd odd?))
(s/def ::small-even-odd (s/and ::even-or-odd #(< % 100)))
(s/valid? ::small-even-odd 1)
; causes
=> ClassCastException clojure.lang.MapEntry cannot be cast to java.lang.Number (Numbers.java:226)
It seems like the anon function is getting a KV pair instead of the value that’s being checked.@eoliphant what’s the result of (s/conform ::even-or-odd 1)
?
that’s what I was thinking, but i didn’t realize that that would ‘carry forward’ into the next spec
Well, you could flip the order. (s/def ::small-even-odd (s/and #(< % 100) ::even-or-odd))
won’t gen then
actually, I guess it won’t gen regardless
you need an int?
at the beginning or something
if i have two functions in the same namespace that i want to spec with req-un
with the same named arg e.g. match
but different shapes, must I put those specs in other namespaces in order to specify the different shapes?
since the spec must be named match
and I can't specify two specs with the same name, e.g.:
(s/def ::match string?)
...
(s/def ::match number?)
if they are req-un why not just give them different namespaces?
right - ::
is a shorthand for the current namespace
ok. guess i wasn't sure if it's appropriate to abandon the ::
convention since all my other specs in that namespace are using it :thinking_face:
it’s ok and fine to do that
fyi, changes coming in this area for next version of spec that should make it less weird
I've never seen any assumption or convention that specs that don't use the current namespace are private
it's a convention in many clojure projects, if the ns has impl as part of its path you know you aren't expected to rely on it as a consumer
core.async is a good example
@alexmiller Are you aware that clojure.spec-alpha2.test/check
is "broken" at the moment?
and I will fix it as soon as I finish getting the next Clojure released :)
beta that is
'kthx
I tried to fix it locally but I haven't quiet gotten my head around the path through the code to figure out exactly what needs changing... yet...
I did not intentionally change anything around this, so it’s something I (unintentionally) broke, but haven’t looked yet
I think it's because stest/check
still, ultimately, calls s/spec
(a macro) and this line in check-1
no longer behaves the same as before:
specd (s/spec spec)]
(I just haven't quite figured out the correct invocation to replace that with)
prob a bug in the s/spec impl
FYI, I tried switching our code over to clojure.spec-alpha2
because, why not? I ran into two speed bumps (so far)...
1. we reuse :clojure.core.specs.alpha/binding
in one of our specs (I got around that by using eval
to s/def
that spec into the new spec's registry).
2. we use A spec that uses test.chuck
and it's wired into clojure.spec.alpha
so I'd need to create a fork of that using the new clojure.spec-alpha2
artifact to make things work.test.chuck
fails with
Caused by: java.lang.IllegalArgumentException: No method in multimethod 'create-spec' for dispatch value: ws.domain.member/bounded-string
Not yet sure what causes that.
(s/def ::email (s/with-gen (s/and (bounded-string 5 128)
wstr/valid-email?)
(wgen/fn-string-from-regex wstr/email-regex)))
(defn bounded-string
"Given min/max lengths, return a spec for a string within
those lengths (inclusive).)"
[from to]
(s/and string? #(<= from (count %) to)))
I have a feeling this is related to the stest/check
failure since it seems to be due to an assumption that a form like (a-fn ...)
can be dispatched on the first argument, rather than evaluating it and dispatching on the result?
yeah, might be missing a case there
If it's any help, I tried this
(defn bounded-string
"Given min/max lengths, return a spec for a string within
those lengths (inclusive).)"
[from to]
(s/and string? #(<= from (count %) to)))
(def ^:private email-bounded-string? (bounded-string 5 128))
and it failed with Exception in thread "main" Syntax error compiling at (ws/domain/member.clj:87:1).
Unable to resolve symbol: from in this context
so at this point I'll give up 🙂