This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

## 2020-03-10

## Channels

- # announcements (1)
- # babashka (44)
- # beginners (188)
- # calva (37)
- # chlorine-clover (28)
- # cider (12)
- # clj-kondo (40)
- # clojars (1)
- # clojure (323)
- # clojure-austin (7)
- # clojure-europe (20)
- # clojure-italy (4)
- # clojure-nl (16)
- # clojure-spec (7)
- # clojure-uk (37)
- # clojuredesign-podcast (1)
- # clojurescript (30)
- # cryogen (2)
- # cursive (30)
- # data-science (1)
- # datomic (26)
- # emacs (1)
- # events (1)
- # figwheel-main (13)
- # fulcro (89)
- # garden (1)
- # graalvm (20)
- # graphql (8)
- # jobs (1)
- # jobs-discuss (1)
- # joker (6)
- # kaocha (125)
- # lambdaisland (1)
- # meander (42)
- # off-topic (18)
- # pathom (3)
- # pedestal (6)
- # shadow-cljs (55)
- # spacemacs (21)
- # sql (18)
- # tools-deps (8)
- # uncomplicate (2)
- # vim (1)
- # yada (3)

Anyone have insight into why the `such-that`

is used here?
https://github.com/clojure/spec.alpha/blob/spec.alpha-0.2.176/src/main/clojure/clojure/spec/gen/alpha.clj#L187

Our tests are occationally failing with "Couldn't satisfy such-that predicate after 10 tries.", and the associated pred is `:pred #object[clojure.core$ratio_QMARK_ 0x62fb2f00 "clojure.core$ratio_QMARK_@62fb2f00"]`

.

there is some mention of such-that failures in gary fredericks' generators video at around 16:16 -- https://www.youtube.com/watch?v=F4VZPxLZUdA

ratios are conceptually goofy because you may or may not want to consider integers to be ratios in a given context
it's useful to think of integers as special kinds of ratios, because almost any use case for ratios should almost certainly apply to integers as well. It's hard to do arithmetic with ratios without bumping into integers inadvertently at least (e.g., `(* 3/4 4/3)`

)
but arguably it would surprise people if `(ratio? 42)`

returned true, so it doesn't; maybe there are other good reasons for this too beyond just surprise
in any case, there's a mismatch because test.check takes the first approach, but `ratio?`

wearing its spec hat obviously has the same semantics as `ratio?`

wearing its predicate hat, and so when you generate from it you don't want to generate integers
I think `(such-that ratio? (ratio))`

could definitely be improved; setting a higher retry threshold would stop the exceptions, but a custom generator would be the best; something like `(gen/let [[n d] (gen/tuple gen/large-integer gen/large-integer)] (let [r (/ n d)] (if (ratio? r) r (/ (inc n) d))))`

there might be some arithmetical edge case there I'm not thinking of, but I think that works

also I forgot to handle `(zero? d)`