clojure-spec

Carlo 2021-10-03T17:19:11.155100Z

is clojure.spec.gen.alpha/let not available in clojurescript?

Carlo 2021-10-03T17:30:29.155700Z

If I try require

[clojure.spec.gen.alpha :as gen :include-macros true :refer-macros [let]]
it will say that there is no macro named let

Carlo 2021-10-03T18:39:05.159200Z

@borkdude just because of the previous link

2021-10-03T18:42:02.159400Z

It doesn't because let is a macro and can't be lazy loaded (I believe that's the reason anyways). You can use the non-macro version, bind which is part of clojure.spec.gen.alpha

2021-10-03T18:45:30.159600Z

Just to clarify, let is not available in the Clojure version of clojure.spec.gen.alpha either.

Carlo 2021-10-03T19:09:18.160Z

@colinkahn if the problem is the lazy loading, can I somehow preload it? Yes, I was trying to use let because it seems cleaner wrt bind and fmap which is what I'm using now. So, are the tutorials outdated? Was let removed from clojure.spec.gen.alpha at some point? I thought I used it in the past 😮

Carlo 2021-10-03T19:10:55.160200Z

moreover, where is this code https://github.com/clojure/test.check/blob/master/src/test/clojure/clojure/test/check/test.cljc#L1054 getting the gen/let?

Carlo 2021-10-03T21:03:22.160500Z

ok, I'm so dumb, I should just have imported clojure.test.check.generators where the let macro I'm interested in is actually defined 🤦‍♂️. Thanks for the help!

2021-10-03T21:04:21.160700Z

Those examples look like just test.check, which specs gen namespace lazy load behind statically defined functions. It's a design decision in spec, that all the functions in the gen namespace can be used without loading clojure.test.check.generators until needed (for example people could define specs for use in production code but only incur loading the test.check.generators namespace in their test suite where they'll use that functionality). In ClojureScript, it's the same but there is no true lazy loading, but you only need to manually require the test.check namespaces when you need them.

🙌 1
2021-10-03T21:04:55.160900Z

^ but yeah if you don't care about this stuff then just import test.check generators like you just posted 😊

🙌 1
Carlo 2021-10-03T21:12:18.161200Z

awesome! Now I understand why the re-export was needed and what's the problem with re-exporting the let macro. Thanks again @colinkahn

👍 1
mafcocinco 2021-10-03T17:43:42.157300Z

I briefly used spec.alpha but didn’t end up doing much with it. I’m interested in using spec2 for message validation in a pub/sub system. Can someone point me to the current “state of the art”/example use cases/best practices/etc. for using spec2?

mafcocinco 2021-10-05T01:55:46.162300Z

after a bit of research, I decided to use metosin/malli. Seems to have all the features I need and I like the data-driven orientation.

bortexz 2021-10-03T17:58:29.158800Z

Currently spec 2 is a work in progres and not ready for production use, so there is not much to be found, but if you’re still interested to give it a try, there’s some info on the github’s repo wiki (https://github.com/clojure/spec-alpha2/wiki), and the talk where Rich talks about it https://www.youtube.com/watch?v=YR5WdGrpoug&ab_channel=ClojureTV

seancorfield 2021-10-03T22:28:35.161700Z

Spec 2 still has a lot of bugs and has gone through a lot of changes -- with a number of additional changes still planned. We have been very heavy users of Spec (1) since it first dropped -- in production code -- and for about three months we ran a branch of our code tracking Spec 2 but it just became intractable to keep tracking it and working around the bugs...

mafcocinco 2021-10-04T03:49:07.161900Z

got it. I will use spec 1 then. thanks.