Re: what's the difference between when and if?

2009-01-24 Thread Vincent Foley
when is like do with only the 'then' branch wrapped in a do: (if foo (do (println "hi") 42))) is the same as (when foo (println "hi") 42) And like if without an else branch, when returns nil if its predicate yields false. On Jan 24, 9:33 am, wubbie wrote: > Here is code from co

Re: what's the difference between when and if?

2009-01-24 Thread e
I use the philosophy, I've got this nice hammer with a nail remover on the back. It's a natural fit that sometimes you want to pull nails out in addition to hammering nails in. For those two jobs, I don't need to be walking around with a special nail-remover-only tool. and if has fewer character

Re: what's the difference between when and if?

2009-01-24 Thread Meikel Brandmeyer
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

Re: what's the difference between when and if?

2009-01-24 Thread wubbie
I know when is a macro and if is a special form. "when" might be more efficient (short-circuit test). Why "when" is used in take and if is used in drop. thanks -sun On Jan 24, 10:35 am, e wrote: > thanks for putting these side by side so I could get an idea what when > does.  Up until now, wh

Re: what's the difference between when and if?

2009-01-24 Thread e
thanks for putting these side by side so I could get an idea what when does. Up until now, when I see "when", my eyes have glazed over. Thus the only reason I need when is to read other people's code. Good question. Is there a reason to have when? On Sat, Jan 24, 2009 at 9:33 AM, wubbie wrote

what's the difference between when and if?

2009-01-24 Thread wubbie
Here is code from core.clj. The question is when to use when or if. (defn take "Returns a lazy seq of the first n items in coll, or all items if there are fewer than n." [n coll] (when (and (pos? n) (seq coll)) (lazy-cons (first coll) (when (> n 1) (take (dec n) (rest coll)