Re: Cleaner solution, anyone?
Exactly! By the way, I posted the same questionhttp://stackoverflow.com/questions/23415815/more-functional-way-to-do-thisto stackoverflow. A. Webb seems to agree with Steve, showing a version using reduced. Thank you for the response, guys! On Friday, May 2, 2014 1:38:09 AM UTC+5:30, Guru Devanla wrote: Neat, so in your last solution are you trying to get rid of recur and solve 1 - (1/2)^x = time ? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Cleaner solution, anyone?
I've been trying out my code in both Clojure http://tryclj.com/ and ClojureScript http://clojurescript.net REPLs. 1. Ratio not being a type in js might cause inconsistencies if not used carefully. (for eg in a web app that uses both clj and cljscript) 2. Lazy sequences in Clojure are lazy in word-sized chunks, whereas ClojureScript appears to be truly lazy. This might be important, because the following code *terminates in clojurescript, but not in clojure*: (take 2 (map state (range))) due to the 2 reasons listed above. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Cleaner solution, anyone?
Neat, so in your last solution are you trying to get rid of recur and solve 1 - (1/2)^x = time ? On Thu, May 1, 2014 at 12:06 PM, Divyansh Prakash divyanshprakas...@gmail.com 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Cleaner solution, anyone?
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 divyanshprakas...@gmail.com 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Cleaner solution, anyone?
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 ja...@booleanknot.com 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 divyanshprakas...@gmail.com 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Cleaner solution, anyone?
Yes, sorry, I didn't mean reduce, I meant reductions. - James On 1 May 2014 21:35, Guru Devanla grd...@gmail.com wrote: 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 ja...@booleanknot.comwrote: 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 divyanshprakas...@gmail.comwrote: 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Cleaner solution, anyone?
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.) true cljs.user= (state 1.9) 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.