Reduce is not lazy, correct? Will it ever return for drop-while to execute.
The problem here is not knowing how many iterations make up the sum, isnt?


On Thu, May 1, 2014 at 1:13 PM, James Reeves <[email protected]> wrote:

> I'd suggest generating an intermediate seq with the summed time:
>
> (defn state [time]
>   (->> (thomsons-lamp)
>        (reduce (fn [[_ t] [onoff dur]] [onoff (+ t dur)]))
>        (drop-while (fn [[_ t]] (< t time)))
>        first second))
>
> - James
>
>
>
> On 1 May 2014 20:06, Divyansh Prakash <[email protected]> wrote:
>
>> Hey!
>> 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?
>>
>> Also, I can't find good code-highlighting tools for blogger/clojure. Any
>> suggestions?
>>
>> --
>> 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.
>>
>
>  --
> 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.
>

-- 
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.

Reply via email to