On Wed, Oct 15, 2008 at 11:20 PM, Parth Malwankar
<[EMAIL PROTECTED]> wrote:
>
> But if I do this in a doto, it doesn't seem to work but
> I don't get any error message.
>
> user=> (doto (new java.lang.String "hello") (toUpperCase))
> "hello"
> user=> (class (new java.lang.String))
> #=java.lang.String

doto returns the original object, not the results of any of the
following method calls.  That means it works well for mutable objects,
where in the end you want the mutated object.  But since Strings are
immutable, methods like toUpperCase are returning a new String, not
mutating the old one.  So all you're getting back is your original
String.

Perhaps -> would work better in this case:

user=> (-> "hello" .toUpperCase (.replace "H" "J"))
"JELLO"

.. would also work, but I pretty much always prefer -> because you can
mix in non-methods, and the methods are clearly indicated with a
leading dot.  In fact, I could imagine lobbying to have .. removed
(while we're making breaking changes...)

--Chouser

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