Hi,

Am 24.01.2009 um 15:33 schrieb wubbie:

The question is when to use  when or if.

'When' does have only one branch, while if has two.

(when test the-branch)
(if test then else)

I use 'when' for side-effects or in case there is only
one interesting branch.

(defn do-something
  [x]
  (when verbose?
    (println "I'm doing something"))
  ...)

Or the take example:

(defn take
  [n coll]
  (when (seq coll)
    ...))

There are style guides, which say:
"Use if for two branch statements and when for
one branch statements."

I've been following this line, but using if for both
is also possible. YMMV.

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to