clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
Aron 2020-04-15T06:53:27.110300Z

This is somewhat different for shadow-cljs, right?

flowthing 2020-04-15T09:28:40.112600Z

I often test my specs in the REPL by doing something like (clojure.test.check.generators/generate (clojure.spec.alpha/gen ::foo)). Sometimes I mess up the spec such that the generator can't generate a value from my spec, and I get Couldn't satisfy such-that predicate after 100 tries.. Is there an easier way to debug cases like this than process of elimination? If the spec is fairly large, it's can be pretty time-consuming and difficult to find the offending spec. The exception and the stack trace aren't of much help.

Aron 2020-04-15T12:38:44.113200Z

'test in the REPL' means you type it in?

flowthing 2020-04-15T12:41:35.113400Z

Well, I evaluate the forms in my editor, but yeah.

Aron 2020-04-15T12:50:27.113600Z

are you by chance using neovim and shadowcljs?

flowthing 2020-04-15T12:50:49.113800Z

Cursive, but I have dabbled with Conjure a bit.

Aron 2020-04-15T12:52:21.114Z

https://github.com/thheller/shadow-cljs/issues/508#issuecomment-565021177 YAY. so i can use conjure finaly

Aron 2020-04-15T12:52:30.114300Z

should've paid attention, it's been MONTHS

Aron 2020-04-15T12:52:46.114500Z

thanks flowthing! : )

2020-04-15T12:56:55.115100Z

somebody needs to write up a summary of what the such-that error means for spec users

2020-04-15T13:07:32.115900Z

@gfredericks It looks like @flowthing knows what it means. The question is: is there an easier way to find it than manual searching?

1🎯
2020-04-15T13:07:51.116300Z

(I’m curious your answer to that as well.)

2020-04-15T13:08:41.117500Z

I don't think so. There's a feature added to such-that that enables spec to give better errors, but that was never implemented in spec

2βœ”οΈ
alexmiller 2020-04-15T13:23:19.117900Z

s/was never/has not yet been/

1πŸ’―5βœ”οΈ
2020-04-15T13:25:42.118900Z

I was uncertain whether these situation with spec2 was similar or not

alexmiller 2020-04-15T13:48:12.119200Z

no changes for this yet

alexmiller 2020-04-15T13:48:29.119900Z

I did a little spike of it a while back but it was less obvious than I expected

mpenet 2020-04-15T13:48:50.120200Z

sorry to ask again: any eta for spec2 ?

alexmiller 2020-04-15T13:59:29.121200Z

no, kind of been dormant recently but we'll be back to it soon I hope

81😱
Aron 2020-04-15T15:12:21.121700Z

well, nope.

2020-04-15T15:12:54.121900Z

It’s pretty much the same, you’d specify the preloads in your build defined in shadow-cljs.edn

2020-04-15T15:14:13.122300Z

Actually yeah, it’s under a different key

seancorfield 2020-04-15T17:02:51.125300Z

Re: such-that -- about the only thing I've found that helps avoid that is relentlessly running s/exercise on each spec as I write it, so that I trip over a "Couldn't satisfy" error at the earliest possible point and therefore have a really small surface of possibilities to investigate/debug. It's not perfect but it helps me, and it fits naturally in with a very tight RDD workflow that has you evaluating every piece of code as you write it.

1πŸ‘
ballpark 2020-04-15T17:18:37.125800Z

Hey Everyone, I would love your input on my SO question: https://stackoverflow.com/q/61234691/59439

vlaaad 2020-04-15T17:43:14.126300Z

Isn't it sort of obvious what specs might throw such-that errors? The ones that use s/and with second condition rejecting most values from the set specified by first condition?

zane 2020-04-15T18:18:45.127200Z

I think it's a good idea to avoid using the word "obvious" in this kind of context. Spec is pretty complicated, and people come to it from a variety of backgrounds.

alexmiller 2020-04-15T18:36:46.128100Z

they both ultimately call the same function so I would expect perf to be pretty similar right now. we have considered fast-pathing a separate valid? path in spec 2 though and I would expect that to be the faster option.

bbuccianti 2020-04-15T18:42:22.128400Z

Could be possible to use spec to validate lambda expressions?

bbuccianti 2020-04-15T18:42:41.128500Z

I mean, I'm building a lambda calculus reducer

bbuccianti 2020-04-15T18:43:29.128600Z

And I'm thinking if would be possible to use property based testing in order to see if it's reducing properly

bbuccianti 2020-04-15T18:43:56.128700Z

But I never used spec and I don't know (yet) if that would be possible

alexmiller 2020-04-15T18:48:47.129700Z

s/fspec is the tool provided, but it's often more trouble than it's worth when using gen

bbuccianti 2020-04-15T18:51:40.129800Z

Do you mean than it doesn't ve of any value building such a thing?

bbuccianti 2020-04-15T18:51:46.129900Z

*be

alexmiller 2020-04-15T18:59:34.130600Z

spec is not particularly useful for checking functions as args in a deep way

Aron 2020-04-15T19:01:57.131500Z

out of curiosity, is there anything that can do that? Sounds like something that I call the halting problem?

ballpark 2020-04-15T19:08:05.131700Z

Got it, thanks!

alexmiller 2020-04-15T19:11:57.131900Z

the big differences are that a) with valid?, you can fail fast and b) with explain, you have to track a lot of additional info and accumulate it for reporting

2πŸ‘
nwjsmith 2020-04-15T19:14:46.132200Z

@ashnur there are several property-based testing tools that can do this, they generate functions that satisfy the function's type

ikitommi 2020-04-15T19:18:35.135500Z

fast-path to valid? is a good idea. Any other new ideas for Spec2? New syntax for fn specs still wip?

Aron 2020-04-15T19:20:59.135600Z

Then I misunderstood what functions as args in a deep way means, sorry.

alexmiller 2020-04-15T21:17:18.136500Z

too many ideas :) fn specs dormant atm, working on other stuff, but we'll get back to it

kenny 2020-04-15T21:47:23.136900Z

Is this a known bug?

(s/def ::foo
  (s/with-gen #(string? %) #(s/gen string?)))
(s/form ::foo)
=> :clojure.spec.alpha/unknown

alexmiller 2020-04-15T21:52:27.137100Z

Yes

alexmiller 2020-04-15T21:52:50.137600Z

Not going to be fixed, but not an issue in spec 2

1
kenny 2020-04-15T21:53:30.138Z

This appears to be an ok workaround:

(s/form (s/spec #(string? %) :gen #(s/gen string?)))
=> (clojure.core/fn [%] (clojure.core/string? %))

seancorfield 2020-04-15T21:54:50.138500Z

@kenny Why use #(string? %) instead of just string??

kenny 2020-04-15T21:55:18.138600Z

For demonstrating the bug, nothing else πŸ™‚

seancorfield 2020-04-15T22:37:50.138800Z

Ah, so it works just fine with string??

kenny 2020-04-15T22:38:00.139Z

Yep

kenny 2020-04-15T22:38:27.139200Z

I encountered this with a spec defined with a #(re-find ...)