Fork me on GitHub
#clojure-spec
<
2018-10-20
>
slipset10:10:03

This is probably working as expected, but why?

slipset10:10:12

So, I’ve created a spec for a function like

slipset10:10:27

(s/def ::reducing-fn (s/fspec :args (s/cat :accumulator any? :elem any?)))

slipset10:10:41

Then, when I ask if a given fn is valid:

slipset10:10:01

(s/valid? ::reducing-fn (fn [x y]) ;; takes forever and ends with a out of heap memory

slipset10:10:13

So it seems (because test.check needs to be a dep for this to run) that spec is using generative testing to verify if the spec is valid.

slipset10:10:49

Hmm, do I actually have a question? No, probably not, I just wanted to state that I was surprised by this, but it’s probably just the way it has to be.

hmaurer10:10:52

Is there a spec which forces a certain value? same as #(= % some-value) but with a built-in generator, etc

taylor10:10:17

You can use a set with the value in it

hmaurer10:10:37

@U3DAE8HMG oh yes sorry, nevermind

hmaurer10:10:47

thanks!

🤝 1
borkdude20:10:42

Seems like some macros/special forms have different ways of catching/reporting insufficient input

user=> (let)
Syntax error macroexpanding clojure.core/let at (4:1).
() - failed: Insufficient input at: [:bindings] spec: :clojure.core.specs.alpha/bindings
user=> (defn)
Syntax error macroexpanding clojure.core/defn at (5:1).
() - failed: Insufficient input at: [:fn-name] spec: :clojure.core.specs.alpha/defn-args
user=> (fn)
Syntax error macroexpanding clojure.core/fn at (6:1).
() - failed: Insufficient input at: [:fn-tail]
user=> (def)
Syntax error compiling def at (7:1).
Too few arguments to def
user=> (if)
Syntax error compiling if at (1:1).
Too few arguments to if

gfredericks22:10:11

your examples are distinguished by whether it's a special form or not

gfredericks22:10:32

I get different results on version 1.10.0-alpha6

gfredericks22:10:41

especially interestingly, (fn*) compiles

gfredericks22:10:27

it seems to produce a function that throws an arity exception on any call