Fork me on GitHub
#clojure-spec
<
2017-12-20
>
sparkofreason21:12:18

If I want to have a macro that will be able to process spec forms defined in ClojureScript, how do I get the forms in the macro definition? s/form will only get the form at run time, and I need it at compile time.

misha21:12:44

will you use it instead of s/def?

sparkofreason23:12:42

No, after s/def. Basically trying to auto-generate destructuring forms based on the spec.

ag22:12:20

Can someone give me an insight to the issue I'm having with our project please. Because of the way how clojure.spec.alpha interacts with clojure.test.check, specifically I'm guessing this part https://github.com/clojure/spec.alpha/blob/master/src/main/clojure/clojure/spec/gen/alpha.clj#L38 it breaks on attempt to use clojure.tools.namespace.repl/refresh, in a project where clojure.test.check.generators being used in .cljc file(s). And that's because Generator record gets redefined, resulting in two different classes. Here's a sample repo that repros that bug (created by my colleague) https://github.com/xiongtx/reload-error-boot. I thought the easy way of fixing it is to stop using clojure.test.check and just use clojure.spec.gen.alpha everywhere. But that doesn't seem to include bunch of things: macros like gen/let and gen/bind, gen/return, gen/pos-int, etc. Basically not using it at all - seems not possible (?) Because of that, CIDER's refresh and clojure.tools.namespace.repl/refrsh are broken, that makes it sort of painful to work with. Can someone suggest a workaround?

gfredericks22:12:09

can you use refresh-all instead?

gfredericks22:12:25

wait why does Generator get redefined at all?

gfredericks22:12:32

refresh shouldn't be reloading library code

ag01:12:18

can you please take a look at https://github.com/xiongtx/reload-error-boot there's something strange going on, I think this deserves to be a JIRA ticket (unless someone already filed one) I can't formulate though exactly what's happening

gfredericks01:12:08

at a glance, my guess is that cider is more enthusiastic about reloading things than tools.namespace is? certainly seems like bad behavior. I don't think tools should reload libraries under normal circumstances. I've never seen tools.namespace do that.

ag01:12:40

it happens also with tools.namespace

ag01:12:03

it's not bug in CIDER

gfredericks12:12:32

you're saying the lack of a standard require makes tools.namespace act as if t.c.generators was a project namespace?

ag16:12:23

¯\(ツ)

ag16:12:49

it seems failing only for .cljc files

ag16:12:29

with shared generators

gfredericks17:12:47

does tools.namespace explicitly announce that it's reloading the generators namespace?

gfredericks17:12:59

(it usually prints which things it's reloading)

ag18:12:35

this is in our project, when you do (require '[clojure.tools.namespace.repl :refer [refresh]]) (refresh)

:reloading ... then list of namespaces
:error-while-loading finops-admin.specs.shared
#error {
 :cause "Assert failed: Second arg to such-that must be a generator\n(generator? gen)"
 :via
 [{:type clojure.lang.Compiler$CompilerException
   :message "java.lang.AssertionError: Assert failed: Second arg to such-that must be a generator\n(generator? gen), compiling:(shared.cljc:72:34)"
   :at [clojure.lang.Compiler$InvokeExpr eval "Compiler.java" 3700]}
  {:type java.lang.AssertionError
   :message "Assert failed: Second arg to such-that must be a generator\n(generator? gen)"
   :at [clojure.test.check.generators$such_that invokeStatic "generators.cljc" 346]}]
 :trace
and long stacktrace

ag18:12:58

note, there's nothing wrong with that generator in finops-admin.specs.shared

ag18:12:02

this is a bug that appears in the .cljc code that's trying to use clojure.test.check.generators

ag18:12:53

if you read the readme in https://github.com/xiongtx/reload-error-boot you'll see detailed explanation

gfredericks19:12:52

But does the list of namespaces you elided contain test.check?

ag19:12:02

yup it does

gfredericks19:12:59

okay, that is what seems buggy to me

xiongtx21:12:19

Seems that this is a known issue w/ tools.namespace. Thanks to @U09LZR36F for pointing this out! https://dev.clojure.org/jira/browse/TNS-45?actionOrder=desc#issue-tabs