Beautiful.
I've found in practice that using doto seems okay at first, but I
commonly have to insert a function call eventually, and end up having
to change a lot of existing code to get rid of the doto's. This has
been painful enough that I've pretty much stopped using doto in code
that's not just one-off stuff in a repl.
--Chouser
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)))
- J.
I think JavaScript's "with" means something slightly different. I
don't remember about Ruby.
But as Stephen pointed out, this is only useful when the methods (or
functions) have side-effects -- their return values are thrown away.
This explains the use of "do" in the original name, and is a good
reason to keep "do" in the new name.
I don't see much wrong with "doto->", though "do-with" or "do->" might
be okay. I'd probably vote against "do-unto-others-as"
--Chouser
+ 1
RK
I wrote something like this too. I called mine >>_ and used _ as the
insert mark.
Here's my implementation:
(defmacro >>_ [& exprs]
(list 'let (apply vector (mapcat (fn [expr] (list '_ expr)) exprs)) '_ ))
user=> (>>_ "Hello" (apply str _ [", " "World!"]))
"Hello, World!"
I used it a couple times after first writing it, but have since failed
to find much use for it. I guess I wouldn't really recommend it.
--Chouser
Under most circumstances you'd get compile errors up front, I think,
and those would be simple to fix.
Wouldn't bother me.
--Chouser
Any thoughts on this as part of the upcoming bit of breaking changes?
In addition, I think having to always use dot-something for methods is
good consistency.
+1.
>
> Rich
>
> >
>
--
Venlig hilsen / Kind regards,
Christian Vest Hansen.