On Oct 21, 2008, at 8:41 AM, mb wrote:

> I'd like to propose the following chimera of doto and ->.
>
> (defmacro doto->
>  [obj & forms]
>  (let [objx (gensym "obj__")]
>    `(let [~objx ~obj]
>       (do
>         ~@(map (fn [f]
>                  (if (seq? f)
>                    `(~(first f) ~objx ~@(rest f))
>                    `(~f ~objx)))
>                forms))
>       ~objx)))

Is the ".." aspect of it the "automatically make a list if it's not  
one" part?

Along the lines of your example, one could do:

(doto-> (JFrame. "Hello Frame")
               (miglayout (JLabel. "Hello Label"))
               .pack
               (.setVisible true))

I like it!

It seems a key thing to remember here is that while this does return a  
useful value, it's primarily a construct for side effects. We're  
calling these Clojure functions because they're compositions of calls  
that have side effects either on the state of obj or on the system as  
a whole (e.g., showing a window). We're throwing away the values  
produced by the individual calls. This is in contrast to "->" where  
each call's result is consumed by the next function in the thread.

As for the name, this operation seems a lot more like "doto" than "->"  
to me. One option is "doto" in a namespace other than "clojure".  
Prefix and suffix "." are both reserved to Clojure, so "doto." is out.  
"do-for-side-effects" seems slightly wordy. "goto" is considered  
harmful. I think if it can't be "doto", "doto->" is a fine name.

Cheers,

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