This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-15
Channels
- # announcements (17)
- # babashka (16)
- # beginners (17)
- # biff (13)
- # cider (63)
- # cljsrn (8)
- # clojure (34)
- # clojure-europe (12)
- # clojure-germany (4)
- # clojure-nl (2)
- # clojure-spec (17)
- # clojure-uk (2)
- # clojurescript (51)
- # code-reviews (1)
- # conjure (15)
- # cursive (16)
- # datomic (10)
- # emacs (4)
- # fulcro (13)
- # graalvm (4)
- # helix (3)
- # introduce-yourself (7)
- # kaocha (2)
- # lsp (4)
- # music (2)
- # off-topic (11)
- # re-frame (2)
- # reagent (3)
- # releases (1)
- # remote-jobs (1)
- # shadow-cljs (21)
- # spacemacs (4)
- # sql (1)
- # vim (2)
Is there a reason that clojure.test.check.generators/let
was left out of clojure.spec.gen.alpha/lazy-combinators
?
It’s a macro iirc
I think there’s actually a ticket about this
As a macro, you can’t do the same dynaload we do with the other combinators
https://ask.clojure.org/index.php/4633/let-ported-from-test-check-let-to-clojure-spec-gen
This is what I could come up with, it feels unwieldly:
(try
(requiring-resolve 'clojure.test.check.generators/let)
(catch Exception _))
(s/def ::prodquint
(s/with-gen
(s/and string? #(re-matches pro-dquint-regex %))
(fn []
(clojure.test.check.generators/let
[pro-quint-hi (s/gen ::proquint)
pro-quint-lo (s/gen ::proquint)]
(str pro-quint-hi "-" pro-quint-lo)))))
are you trying to produce code that still works if test.check isn't available? if so I can't see how your code accomplishes that
and if not, then I'd think you could just require let
in the more vanilla fashion and everything would be fine
That is what I am trying, and failing, to accomplish. I want the spec to be there with its generator attached to it. Knowing that the generator will only be used int dev/test.
if you want the let
call in the same spot as your spec then I think you basically end up needing eval
or something equivalent
well maybe not
this might work
(defmacro tclet
[& args]
(let [e (try
(requiring-resolve 'clojure.test.check.generators/let)
nil
(catch Exception e e))]
(if e
`(throw (Exception. ~(.getMessage e)))
`(clojure.test.check.generators/let ~@args))))
does it work does it work?