Fork me on GitHub
#clojure-spec
<
2016-06-02
>
stathissideris00:06:10

but as I expected, you lose conform destructuring and explain can't explain the problem anymore

stathissideris00:06:36

...so different solutions would be welcome

george.w.singer00:06:25

Clojurescript is failing to compile my file if my fdefs are located above their corresponding defns. Is this the way things are intended?

george.w.singer00:06:33

I.E., you can't spec your function before you define it?

kenny00:06:55

@george.w.singer: Yes. The var is not defined yet. You could declare the var if you must write the spec above the function. I have just been writing my specs below my function definitions.

george.w.singer00:06:13

Macro sugar needs to be added to spec IMO

george.w.singer00:06:31

(fn-spec
 fn-name ::arg1, ::arg2 -> ::ret-spec 
                             :such-that    ::ret-value-greater-than-max-of-its-inputs)
This would at once declare our fn-name and annotate it with corresponding specs using intuitive Haskell-like syntax.

stathissideris00:06:04

@george.w.singer: you could write that macro 🙂

arohner00:06:41

@george.w.singer: I think that’s a CLJS-impl bug, I’d report it

arohner00:06:06

in CLJ, you can (s/fdef new-fn) ahead of the var

kenny00:06:15

@george.w.singer: Does it work if you do

(s/fdef 'your-sym
        :args ...
        :ret ...)

george.w.singer00:06:35

It does sometimes but then the whole thing becomes buggy. Sometimes it doesn't compile. All tests pass

george.w.singer00:06:46

Really strange behavior is exhibited

george.w.singer00:06:03

The strange behavior goes away if put them before

kenny00:06:39

I seem to be getting a strange error when creating a spec for a function with a type hinted argument. Error:

java.lang.ClassCastException: clojure.spec$spec_checking_fn$fn__11414 cannot be cast to clojure.lang.IFn$DO
Example:
(defn bar
  [f]
  (f 0.0))

(s/fdef bar
        :args (s/cat :f fn?)
        :ret number?)

(defn foo
  [^double value]
  (bar (fn [_] value)))

(s/fdef foo
        :args (s/cat :v number?)
        :ret number?)

(defn foo2
  [value]
  (bar (fn [_] value)))

(s/fdef foo2
        :args (s/cat :v number?)
        :ret number?)

(foo 1.0) => error
(foo2 1.0) => 1.0

(s/instrument-all)

kenny00:06:10

Problem exists in 1.9.0-alpha4.

seancorfield02:06:05

Looks like primitive hinting encodes the argument and return type to be encoded in the underlying type (if you add ^double as a return type hint, the cast is to IFn$DD, for example).

seancorfield02:06:34

Very surprised to see that calling an instrumented function can actually load and call clojure.test.check to do generative testing as part of the conformance test, without explicitly calling clojure.spec.test/run-all-tests etc.

stathissideris07:06:57

is this a bug?

spec> (gen/sample (s/gen #{1 0}) 10)
(0 0 1 0 0 0 1 0 1 0)
spec> (gen/sample (s/gen #{false true}) 10)
(true true true true true true true true true true)

hiredman08:06:10

s/gen takes a spec, which is a predicate

hiredman08:06:36

#{false true} will only return true, as a predicate, for true

stathissideris08:06:09

@hiredman: thanks for your explanation, but I still don't get how I would generate true/false randomly

slipset08:06:31

I’ve defined these specs and vars

slipset08:06:35

(s/def ::point (s/cat :x number? :y number?))
(s/def ::body (s/+ ::point))
(s/conform ::point [2 3])
(s/conform ::body [[2 3]])
(s/explain ::body [[2 3]])

slipset08:06:20

::point conforms nicely, but ::body does not conform, and the explanation is:

slipset08:06:39

In: [0] val: [2 3] fails spec: :snake-game.utils/point at: [:x] predicate: number?

slipset08:06:23

I would have thought that (s/+ ::point) would mean one or more points?

stathissideris08:06:30

@slipset: (s/def ::point (s/spec (s/cat :x number? :y number?)))

stathissideris08:06:27

The combination of s/+ and s/cat means that body is defined as a series of :xs and :ys without nesting

slipset08:06:38

thanks 🙂

stathissideris08:06:58

for the record, I ended up with this for booleans:

(defn- boolean? [x] (instance? Boolean x))
(s/def ::boolean (s/with-gen boolean? #(gen/boolean)))

stathissideris09:06:04

is there any way to make s/cat specs generate a vector?

surreal.analysis20:06:00

This is a pretty minor note, but this appears to be one of the only channels with _ separation instead of -. Any chance an admin could change that?

arohner20:06:33

and as we all know, clojure names should prefer - to _

seancorfield20:06:35

I see no stinkin’ underscores here...