Fork me on GitHub
#clojure-spec
<
2016-06-04
>
nwjsmith15:06:57

I'd like to ship a library without requiring test.check, and have the generators dynamically loaded as they are with clojure.spec, but I can't figure out how to do that. Do I wrap all calls to clojure.spec.gen functions in clojure.spec.gen/delay?

nwjsmith15:06:40

(the library is essentially a bunch of specs, some of which require custom generators)

hiredman18:06:51

that is kind of interesting to think about, if you are defining custom specs with generators in your source, then test.check needs to be a regular dependency not a test scoped dependency

hiredman18:06:20

a delay delays runtime code from running, not compile time stuff

hiredman18:06:24

like var resolution

hiredman18:06:48

you likely need some combination of something like dynaload from clojure.spec.gen and the delay there and maybe clojure.core/delay

bbloom18:06:36

or just put your generators in another namespace?

hiredman18:06:18

that would still have issues with any kind of tooling that loads all namespaces (in the absence of test.check)

bbloom18:06:53

what kind of tooling does that? seems kinda like a bad idea 😛

hiredman18:06:30

I was thinking of stuff like lein check, but that only loads stuff from the current project

bbloom18:06:29

on another track…. 1st order predicate expressions and regular languages are closed under intersection — would be cool if somebody wrote an ‘intersect’ function for spec, could be useful for static analysis

bbloom18:06:20

@arohner: well you could just write an abstract interpreter that walks the clojure AST and instead of an environment of symbols -> values, have an environment of symbols -> specs

bbloom18:06:31

each time you use something, you call intersect on it

bbloom18:06:37

if the result is void, you have a "type error"

arohner18:06:52

yeah, just wasn’t sure what you meant by intersect

arohner18:06:56

I have about half of that written

arohner18:06:25

currently reimplementing the regex part of spec to handle it

bbloom18:06:58

if each spec defines a set, intersect = set intersection

bbloom18:06:37

intersecting two predicates is just and-ing them, but you could do better for some predciates, cat, repeat, alt, etc

arohner18:06:58

yeah, it’s a lot more work than that 🙂

bbloom18:06:30

certainly not trivial, but should be at least straightforward, no?

arohner18:06:49

parsing specs and the regex stuff is straightforward, but a ton of code

arohner19:06:04

same w/ flowing predicates through a fn body

bbloom19:06:20

yeah, i have a clojure interpreter that i’ve copy/pasted and modified 4 or 5 times for code walking purposes - someday i’ll make it a library

bbloom19:06:57

the transform namespace is an example of a code walk on that ast & you could replace that with a type check walk

arohner19:06:36

I’m already walking the tools.analyzer output, so it’d be a good amount of work to swap

bbloom19:06:12

not suggesting that you switch to my thing 😛 just showing that it can be much less code than tools analyzer, which does all the analysis all at once

bbloom19:06:58

anyway @arohner: excited to see what you come up with 🙂

arohner19:06:24

yeah, me too. Just need to finish the regex matching crap

gfredericks21:06:45

the first big question about clojure.spec that I'm going to try to dive into is how I can get functionality similar to https://github.com/gfredericks/schema-bijections

gfredericks21:06:26

so I suspect (ha!) I'll be reading a bunch of the clojure.spec source soon

gfredericks21:06:54

is it weird that s/tuple takes preds instead of specs?

benzap22:06:56

I thought preds were specs

benzap22:06:54

I have a tuple '(s/def ::color (s/tuple ::byterange ::byterange ::byterange ::byterange))' that seems to work @gfredericks

benzap22:06:00

as of now, I have successfully converted my project from plumatic.schema to cljs.spec!

benzap22:06:19

still have a lot to learn about it, but it sure is nice

gfredericks23:06:09

benzap: yeah it does seem to work, but that means the docs are misleading I think: preds are specs but specs aren't preds