Re: Seeking critique of "pattern" in clojure.spec (LONG)

2017-04-11 Thread Brian Beckman
I should have called them "blueberries" instead of the more provocative "virtual times." I was trying to go from an abstract mathematical definition to a formalization in Clojure. Eventually, virtual times will be part of a discrete-even simulation platform, but it's too early to say much

Re: Seeking critique of "pattern" in clojure.spec (LONG)

2017-04-10 Thread Didier
Here it is adapted to use a deftype: https://gist.github.com/didibus/2ccd608ed9d226039f944b02a10f9ad5 I gather from your solution that "orchestra" is not needed to spec :ret > types? > It is not. The return spec will be used during st/check. If you want the return spec to be validated outside

Re: Seeking critique of "pattern" in clojure.spec (LONG)

2017-04-10 Thread Brian Beckman
Wow... that's a comprehensive solution, Didier :) Bravo! It's a good lesson for s/fdef, which I haven't yet studied. I gather from your solution that "orchestra" is not needed to spec :ret types? As to semantics, on the one hand, I can spec ::virtual-time as a light overlay over Double and

Re: Seeking critique of "pattern" in clojure.spec (LONG)

2017-04-10 Thread James Reeves
Using the preset infinity constants is probably the best solution in this case. :) - James On 11 April 2017 at 01:50, Brian Beckman wrote: > James -- just the kind of simplification I was looking for! In fact, I > think the following will do everything I need --- generate

Re: Seeking critique of "pattern" in clojure.spec (LONG)

2017-04-10 Thread Didier
I agree with James, here's what I'd do: https://gist.github.com/didibus/d0228ffad9b920c201410806b157ff10 The only downside, and why you might still want to use types (probably with deftype), is to prevent people from using standard functions like <,>,= etc. If you deftyped virtual-time, it

Re: Seeking critique of "pattern" in clojure.spec (LONG)

2017-04-10 Thread Brian Beckman
James -- just the kind of simplification I was looking for! In fact, I think the following will do everything I need --- generate numbers avoiding only NaN (which isn't equal to itself, nor less than anything) (s/def ::virtual-time (s/with-gen (s/and number? #(not (Double/isNaN %)))

Re: Seeking critique of "pattern" in clojure.spec (LONG)

2017-04-10 Thread James Reeves
I think what you have is overly complex for what you want to do. Consider this alternative spec: (s/def ::virtual-time (s/or :number number?, :limit #{::infinity- ::infinity+})) Then we write a comparator: (defn compare-times [a b] (cond (= a b) 0 (= a ::infinity+) +1

Re: Seeking critique of "pattern" in clojure.spec (LONG)

2017-04-10 Thread Brian Beckman
These are good comments that give me things to think about. I'm grateful. * The pattern concerned me because (1) it was just the first thing I came up with, so not sure there wasn't a better way staring me in the face (2) I didn't see any clearly better alternatives, so not sure whether I just

Seeking critique of "pattern" in clojure.spec (LONG)

2017-04-10 Thread Didier
I think this pattern is fine. What specifically about it annoys you? You could do it without records, but then you wouldn't be creating a type. Do you really need a type? The advantage of types in Clojure are that they let you do polymorphic dispatch of them. So they are useful if you have

Seeking critique of "pattern" in clojure.spec (LONG)

2017-04-10 Thread Brian Beckman
"I apologize for the length of this post ..." Blaise Pascal? I am seeking critique of a certain "programming pattern" that's arisen several times in a project. I want testable types satisfying a protocol, but the pattern I developed "feels" heavyweight, as the example will show, but I don't