On Mar 4, 2009, at 3:56 AM, Rich Hickey wrote:

>>
>> Conversely, "when" says "side effect". This is clear for 2 reasons.
>> First, there is no "else" clause, so "when" doesn't really work as an
>> expression. Furthermore, the forms in the "when" body are evaluated
>> in an implicit "do". Since only the final value is returned, any of
>> the earlier expressions in the "when" body are useful only for their
>> side effects.
>>
>
> This is not the convention in Clojure for a couple of reasons.
>
> First, there are far fewer side effects. 'when' does not say side
> effects, although as you point out, it does support them. But then, so
> do function bodies and they don't inherently say side-effects.
>

Rich,

You're obviously the wrong guy to argue with regarding what the  
"right" way to do stuff in Clojure is, so I'll take your comment to  
heart.

At the same time though, I still don't quite get why "when" by  
definition evaluates its subexpressions in an implicit "do" (as CL's  
WHEN provides an implicit PROGN). There is no point in evaluating  
multiple expressions unless they produce side effects: printing to  
the screen, writing to disk, etc... Since this is the defined  
semantics of "when" it seems this should be a flag that governs how  
"when" is used. I understand that there is far less mutability in  
Clojure, but that's not to say there aren't side effects.

> I agree 'if' should always have 3 subexpressions, all the more reason
> to use 'when' when the second is going to be nil. Idiomatic Clojure
> code is full of expressions like:
>
> (when there-is-stuff (expr stuff))
>
> Which I read as when there is stuff, some function of it, else
> nothing. There's nothing inherently side-effecting about it.
>

Again here I'm not sure what you mean by "else nothing". If you're  
using "when" as an expression, it has to produce a value even when  
the test fails. Why not just use "if" and make that value explicit?

> It would certainly be a waste of 'when' in Clojure to reserve it for
> side effects, since so much code contains none.
>

It was 50 years ago today that John McCarthy's description of Lisp   
was published in an AI Memo (AIM-8). Here's to McCarthy and Lisp. And  
here's to you, RIch, for carrying on the flame.

Aloha,
David Sletten


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

Reply via email to