Welcome! Please see the About page for a little more info on how this works.

0 votes
in Spec by

{{clojure.spec/double-in}} defines a spec that tests whether a double is greater than or equal to a minimum value and less than or equal to a maximum value. This seems like an arbitrary choice from the point of view of mathematics and practical concerns. Sometimes you need to test whether a double is greater than a minimum or less than a maximum. Example: The application will divide by the tested double later.

Of course we can add tests to {{double-in}}, e.g. like

(s/and (s/double-in :min 0.0 :max 1.0) #(not= 0.0 %))}}



(and (> % 0.0) (<= % 1))


might be clearer if {{double-in}}'s {{NaN}} and {{Infinity}} tests aren't needed.

Why not have a common interface to all four interval tests? Rather than four different spec functions, which is one option, I suppose, I suggest adding two keywords to {{double-in}}. When true, these would change the >= or <= tests to > or < tests:


(or? :min+, :min-greater-than, :greater-than-min, :strict-min, :min-open, or possibly :infinmum, :inf, but that could be misleading)


(or :max- :max-less-than, :less-than-max, :strict-max, :max-open, or possibly :supremum, :sup etc.)

For example,

(s/valid? (s/double-in :min 0.0 :max 0.1 :min-greater true) 0.0)

would return {{false}}, but

(s/valid? (s/double-in :min 0.0 :max 0.1 :min-greater false) 0.0)

would return {{true}}.

Default values for these keywords should probably be false, for compatibility with the current definition of {{double-in}}.

1 Answer

0 votes
Reference: https://clojure.atlassian.net/browse/CLJ-1984 (reported by alex+import)