Fork me on GitHub
#clojure-spec
<
2017-01-15
>
bbloom18:01:51

@rickmoynihan that’s a decent hint to programmers, but it’s not quite good enough semantics

bbloom18:01:11

for example, a generator will produce arbitrary values there, which is clearly wrong

bbloom18:01:44

oh well actually maybe spec isn’t aware of aliasing and you’ll get an error

bbloom18:01:46

let me see...

bbloom18:01:30

this works: (def unspeced (fn [x] true))

bbloom18:01:39

breaks the generator, which is what i’d expect

dottedmag21:01:19

Is there a way to drill into specs from REPL? Say, an output from (doc ns) gives args: (cat :name simple-symbol? :docstring (? string?) :attr-map (? map?) :clauses :clojure.core.specs/ns-clauses), how do I see the definition of :clojure.core.specs/ns-clauses spec?

dottedmag21:01:28

Oh, (doc :clojure.core.specs/ns-clauses) works 😄

joshjones21:01:23

this is effectively the same as (s/describe :clojure.core.specs/ns-clauses) fyi

bbloom22:01:54

some specs seem to resolve eagerly, some lazily - is there some way to force laziness for the sake of forward references?

bbloom22:01:04

ie if i do (s/def ::foo ::bar) that fails

bbloom22:01:12

but (s/def ::foo (s/and ::bar) works

bbloom22:01:21

which seems like a quirky way to accomplish this....

bbloom22:01:02

i was hoping s/spec would do it, but sadly it resolves eagerly

rickmoynihan23:01:58

> that’s a decent hint to programmers, but it’s not quite good enough semantics for example, a generator will produce arbitrary values there, @bbloom: What else could a generator do though? As far as I can see it can only explicitly fail or generate a likely incorrect value

bbloom23:01:16

i’d want it to fail

bbloom23:01:06

i kinda also want to be able to test things w/ incomplete specs - like if i have (s/or :foo string? :bar some-crazy-thing?) i should at least be able to test the :foo path, even if :bar isn’t tested

bbloom23:01:08

although i’d expect a warning

rickmoynihan23:01:47

bbloom: then maybe just use the generator (fn [] (throw (ex-info “Unspeced function”))

bbloom23:01:01

that solves the conform/instrument case (modulo fspec) but not quite the partial generator case - which i guess would require some changes to the generator monad thing? i dunno if it supports filtering

bbloom23:01:20

generator would be like (fn [] (warn “unspeced function”) (skip))

rickmoynihan23:01:07

yeah - was just thinking you want them to flow

rickmoynihan23:01:50

it seems you want something a little like a prolog cut

bbloom23:01:12

a little 😉

rickmoynihan23:01:40

yeah might be the opposite of that 🙂

bbloom23:01:09

i haven’t looked too deeply at writing generators yet, so i don’t know what the monad thing is about - i imagine it’s like mfilter or something

rickmoynihan23:01:32

its not something I’ve looked into

bbloom23:01:15

ah yeah, it’s “MonadPlus” - basically you just lift map in to mapcat

bbloom23:01:30

ie you had map x -> y, now you have map x -> [y] and then you can filter by doing map x -> []

bbloom23:01:37

i dunno if the generators support that or not 🙂

bbloom23:01:42

i assume they must

bbloom23:01:29

since they are generating multiple possible things

bbloom23:01:54

but they might expect exaclty one item at a time, not zero-or-one item

bbloom23:01:34

MonadPlus provides the “zero” value, ie [] for the list monad or just an empty stream of generated data

rickmoynihan23:01:37

I’m still trying to get my head around exactly what being a partial generator means… presumably it’s just something like (s/or :walk gen-me :don-walk unspecced-gen-ignore-me)

bbloom23:01:03

well, you’d walk it, but emit a warning and then not actually generate anything

rickmoynihan23:01:04

(semantically - rather than in practice)

rickmoynihan23:01:53

why walk it? rather than ignore it?

bbloom23:01:15

i guess that’s the same thing

gfredericks23:01:52

gen/such-that is the monad-plus part

bbloom23:01:14

is the warn & skip idea doable?

gfredericks23:01:27

but it's not really monad-plus since it will just give up if it can't get the pred to pass

gfredericks23:01:05

@bbloom warn and skip just applies to s/or specs?

bbloom23:01:31

that’s where it would be most useful, but i don’t see why it wouldn’t apply to any spec… for example:

bbloom23:01:48

(s/exercise unspeced)

bbloom23:01:09

that’d just print something like “skipping unspeced at []"

bbloom23:01:25

something like that at least

bbloom23:01:58

for s/or specs it would be much more useful b/c i could run partial tests

gfredericks23:01:24

sounds possible, sure

rickmoynihan23:01:52

can’t a spec be included anywhere though? And anywhere you include an unspeced spec wouldn’t it imply the specs had to effectively be rewritten to use an s/or over it?

bbloom23:01:48

yeah - specs are implicitly a big and/or tree

rickmoynihan23:01:27

but just thinking the s/and with an unspec in implicitly also becomes an unspec

rickmoynihan23:01:48

i.e. its contagious like a type