Re: idiomatic way to use cond.

2009-12-28 Thread Jeff Rose
I can think of a couple ways to break it up.  First, you can pull the
expressions inside of each do form out into separate functions.
Whether they are defined above the current function or inside it using
let, both would clean it up and give a label to each of the groups of
expressions (the function name).  Otherwise if you have duplicated
expressions in the do forms, then you could do the minimum amount
possible in the cond and put it in a let to keep the return value, and
then use it to execute the rest of the code within the body of the
let.  One of those seems to work for me most of the time, but I could
be missing something too...

Cheers,
Jeff

On Dec 28, 4:59 am, RD rdsr...@gmail.com wrote:
 Hello All,
       When every I write clj code that involves cond. It always involves a
 do in almost all of the classes.

 somethiing like
    (cond
         condition1 (do exp1 exp2 exp)
         condition2 (do exp1 exp2 ...)
         true (do ...))

 Is there a better way (without the explicit do) to write this??

 regards,
 rdsr

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


Re: idiomatic way to use cond.

2009-12-28 Thread Meikel Brandmeyer
Hi,

Am 28.12.2009 um 04:59 schrieb RD:

(cond
 condition1 (do exp1 exp2 exp)
 condition2 (do exp1 exp2 ...)
 true (do ...))
 
 Is there a better way (without the explicit do) to write this??

Since the results of exp1 up to expN-1 are thrown away you are doing them only 
for side effects. Try to restructure your code in a more functional fashion, so 
that you get (let [res1 exp1 res2 exp2 ...] (expN resN-1)). Then tho do will be 
gone. If the side effects are necessary (eg. I/O) the ugly do should remind you 
of this.

If the expression chain gets too long, you should refactor them in their own 
functions.

Sincerely
Meikel

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


idiomatic way to use cond.

2009-12-27 Thread RD
Hello All,
  When every I write clj code that involves cond. It always involves a
do in almost all of the classes.

somethiing like
   (cond
condition1 (do exp1 exp2 exp)
condition2 (do exp1 exp2 ...)
true (do ...))

Is there a better way (without the explicit do) to write this??

regards,
rdsr

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