On Oct 16, 2008, at 7:29 AM, Rich Hickey wrote:

> Another semantic marker here is 'do'. do in Clojure implies side-
> effects. Since you can't uppercase a string by side effect, doto isn't
> the right tool for this job.


Neat.

I explored the "do..." marker a little with Clojure:

        - user=> (filter #(re-matches #"do.*" %) (map #(-> % first name) (ns- 
publics 'clojure)))
          ("dorun" "doseq" "dosync" "dotimes" "doubles" "doto" "double-array"  
"doall" "double" "doc")

         The "do implies a side-effect emphasis" pattern holds for dorun,  
doseq, dosync, dotimes, doto, and doall.

        - The doc for the function "repeatedly" mentions "presumably with  
side effects", but it doesn't begin with "do".

        - The special form "do" is just about grouping, independent of side  
effects.

I recently changed the clojure.contrib.sql/with-results macro to  
remove a "doseq" call. Now it just provides the sequence of results  
and lets the caller decide what to do with it which is a lot more  
flexible.

Coming from an imperative programming mindset, I find that imperative/ 
side-effecting is often the first thing that occurs to me. When I work  
on the code to make it more functional, it's pretty much uniformly an  
improvement in how flexible and composable it is.

As a very welcome bonus, I'm also finding it's a lot more fun!

--Steve


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to