> I wrote a blog post discussing Thomson's Paradox, and simulated it in Clojure-
> http://pizzaforthought.blogspot.in/2014/05/and-infinity-beyond.html
>
> The state function defined towards the end is not very functional.
> Could someone guide me towards a cleaner approach?
Here's an option:
(defn state [t]
(reduce (fn [[v0 t0] [v1 dt]]
(cond (zero? dt) (reduced "unknown")
(> t0 t) (reduced v0)
:else [v1 (+ t0 dt)]))
[true 0]
(thomsons-lamp)))
cljs.user=> (state 0)
true
cljs.user=> (state 0.99)
true
cljs.user=> (state 1)
false
cljs.user=> (state 1.49)
false
cljs.user=> (state 1.5)
true
cljs.user=> (state 1.9999)
true
cljs.user=> (state 1.99999)
false
cljs.user=> (state 2)
"unknown"
cljs.user=>
--Steve
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.