Fork me on GitHub
#clojure-spec
<
2016-07-30
>
lvh00:07:26

I can’t seem to find long? either

eggsyntax00:07:30

int? will capture all fixed-precision integers. It would still be nice to have a bigint? pred so that the generator specifically produces bigints.

lvh00:07:04

ah, gotcha

lvh00:07:06

thanks 🙂

gfredericks00:07:11

@lvh I don't mind the top level namespace for things that are pretty useful/general

lvh00:07:34

gfredericks: OK works for me

Alex Miller (Clojure team)01:07:21

Doesn't integer? map to that?

Alex Miller (Clojure team)01:07:43

Oh you want just bigints

seancorfield01:07:50

(s/and int? (s/conformer bigint)) perhaps?

seancorfield01:07:19

boot.user=> (s/exercise (s/and int? (s/conformer bigint)))
([-1 -1N] [0 0N] [0 0N] [0 0N] [4 4N] [4 4N] [-12 -12N] [-45 -45N] [4 4N] [-63 -63N])

seancorfield01:07:03

BTW @alexmiller I think the docstring on s/conformer is very confusing about its intent...

seancorfield01:07:15

"takes a predicate function with the semantics of conform i.e. it should return either a (possibly converted) value or :clojure.spec/invalid, and returns a spec that uses it as a predicate/conformer"

seancorfield01:07:37

Because the function argument it takes isn’t really a "predicate function"… that makes it sound like it should be something like int?...

seancorfield01:07:29

…perhaps if it said "takes a conforming function i.e., it should return either a (possibly converted) value or :clojure.spec/invalid"…?

seancorfield01:07:50

(predicate is pretty much otherwise used for functions that return truthy / falsey values in the Spec docs I think?)

seancorfield01:07:15

& and and take predicates, fdef’s :ret, merge, spec

seancorfield01:07:57

(although there is mention in a couple of places that some of those "predicate" contexts may also conform the value… so it’s not entirely clear what’s intended)

seancorfield01:07:43

@lvh @eggsyntax I tested and it looks like you can use (s/and (s/double-in …) (s/conformer bigdec)) if you wanted BigDecimals — and (s/conformer rationalize) if you wanted ratios… and the example above produces big ints

seancorfield01:07:45

Oh, simpler: (s/exercise bigdec?) — didn’t realize there was a direct generator for that

seancorfield01:07:05

and (s/exercise ratio?) ...

seancorfield01:07:25

So bigint? is kind of the only missing one...

eggsyntax01:07:10

Oh, interesting. I was thinking something roughly like (s/with-gen int? (gen/fmap #(bigint %) int?)) (that's just offhand & may have errors; I don't have a repl at hand).

seancorfield01:07:14

Using s/conformer seems simpler… but now Alex has made me question whether that’s entirely valid 😸

seancorfield01:07:08

We use s/conformer as a way to map input field formats to domain model formats along with specs for input fields. We’re now using specs as part of input validation and as part of our domain model testing.

eggsyntax01:07:14

Nice. I haven't really played with s/conformer yet (although I'm certainly making use of s/conform).

lvh01:07:36

@seancorfield: great, thanks 🙂

lvh01:07:08

@alexmiller: I’m OK with any integer; I didn’t realize integer? had been introduced and was using int?

Alex Miller (Clojure team)02:07:12

integer? is old, int? is the new one

dryewo09:07:52

It seems that :ret is not checked at all currently:

(defn foo [x] x)
(s/fdef foo
  :args (s/cat :x int?)
  :ret string?)
(stest/instrument `foo)
(foo 1)

dryewo09:07:17

what am I doing wrong?

dryewo09:07:20

if I put string? into :args, it throws as expected.

dryewo09:07:29

I’m using alpha10

dryewo09:07:05

However, when I run (stest/check foo)`, it complains about wrong :ret. Should it be this way, only checked while testing?

dryewo09:07:55

okay, never mind

seancorfield17:07:00

@dryewo: yes, instrument is to test that functions are called correctly, check is to test that functions are implemented correctly.