Re: How to simplify cond statements

2010-10-30 Thread andrei
On Oct 29, 11:39 pm, Joop Kiefte iko...@gmail.com wrote: (first (flatten ...)) ? And where reduction of code is? -- 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

Re: How to simplify cond statements

2010-10-29 Thread andrei
On Oct 29, 4:03 am, lprefonta...@softaddicts.ca wrote: user= (doc ffirst) - clojure.core/ffirst ([x])   Same as (first (first x)) nil user= That could help a bit : Nice! I didn't know about this function, and for this concrete case it is ideal! -- You

Re: How to simplify cond statements

2010-10-29 Thread andrei
On Oct 29, 4:03 am, Andrew Gwozdziewycz apg...@gmail.com wrote: I'd hoist the empty out of the cond using an if: (if (empty? ps)     ret     (let [fps (first (first ps))]         (cond             ...))) Yeah, I thought about it, but it is still a bit verbose, especially with a 3

Re: How to simplify cond statements

2010-10-29 Thread andrei
On Oct 29, 5:40 am, David Sletten da...@bosatsu.net wrote: You could just bind another local variable in the loop form: (loop [ps pairs        ret {}        ffps (ffirst ps)]   (cond (empty? ps) ret         (some-test ffps) (recur (rest ps) (add-to-result ret ffps) (ffirst (rest ps)))  

Re: How to simplify cond statements

2010-10-29 Thread Meikel Brandmeyer
Hi, On 29 Okt., 12:11, andrei andrei.zhabin...@gmail.com wrote: You could just bind another local variable in the loop form: (loop [ps pairs        ret {}        ffps (ffirst ps)]   (cond (empty? ps) ret         (some-test ffps) (recur (rest ps) (add-to-result ret ffps) (ffirst

Re: How to simplify cond statements

2010-10-29 Thread Andrew Gwozdziewycz
On Fri, Oct 29, 2010 at 7:14 AM, Meikel Brandmeyer m...@kotka.de wrote: There's nothing stoping you to put a let in a loop. (loop [ps  (seq pairs)       ret {}]  (let [ffps (ffirst ps)]    (cond      (not ps)         ret      (some-test ffps) (recur (next ps) (add-to-result ret ffps))    

Re: How to simplify cond statements

2010-10-29 Thread Andrew Gwozdziewycz
Errr... clarification Scheme would blow up when doing (first (first object that could be '())). On Fri, Oct 29, 2010 at 7:44 AM, Andrew Gwozdziewycz apg...@gmail.com wrote: On Fri, Oct 29, 2010 at 7:14 AM, Meikel Brandmeyer m...@kotka.de wrote: There's nothing stoping you to put a let in a

Re: How to simplify cond statements

2010-10-29 Thread andrei
On Oct 29, 2:14 pm, Meikel Brandmeyer m...@kotka.de wrote: There's nothing stoping you to put a let in a loop. Yes, but imagine a bit more complicated case, for example, instead of '(first (first ps))' write (.foo (first ps)), and it will crash. I'm looking for elegant, but general case

Re: How to simplify cond statements

2010-10-29 Thread Joop Kiefte
(first (flatten ...)) ? 2010/10/29 andrei andrei.zhabin...@gmail.com: On Oct 29, 2:14 pm, Meikel Brandmeyer m...@kotka.de wrote: There's nothing stoping you to put a let in a loop. Yes, but imagine a bit more complicated case, for example, instead of '(first (first ps))' write (.foo (first

How to simplify cond statements

2010-10-28 Thread andrei
Hi, I have a code similar to this: (def pairs (list [1 :a] [2 :b] [3 :c])) ... (loop [ps pairs, ret {}] (cond (empty? ps) ret (some-test (first (first ps))) (recur (rest ps) (add-to- result ret (first (first ps :true (recur (rest ps) (do-smth-else ret (first

Re: How to simplify cond statements

2010-10-28 Thread lprefontaine
user= (doc ffirst) - clojure.core/ffirst ([x]) Same as (first (first x)) nil user= That could help a bit : Luc P. andrei andrei.zhabin...@gmail.com wrote .. Hi, I have a code similar to this: (def pairs (list [1 :a] [2 :b] [3 :c])) ... (loop [ps pairs,

Re: How to simplify cond statements

2010-10-28 Thread Andrew Gwozdziewycz
I'd hoist the empty out of the cond using an if: (if (empty? ps) ret (let [fps (first (first ps))] (cond ...))) On Thu, Oct 28, 2010 at 8:49 PM, andrei andrei.zhabin...@gmail.com wrote: Hi, I have a code similar to this: (def pairs (list [1 :a] [2 :b] [3 :c]))

Re: How to simplify cond statements

2010-10-28 Thread David Sletten
Andrei, You could just bind another local variable in the loop form: (loop [ps pairs ret {} ffps (ffirst ps)] (cond (empty? ps) ret (some-test ffps) (recur (rest ps) (add-to-result ret ffps) (ffirst (rest ps))) :true (recur (rest ps) (do-sth-else ret ffps) (ffirst