On Mon, Jan 12, 2009 at 11:15 AM, Michael Reid <kid.me...@gmail.com> wrote: > > On Sun, Jan 11, 2009 at 9:12 PM, Mark Triggs <mark.h.tri...@gmail.com> wrote: >> >> I've also found this useful for accessing members in nested maps. For >> example: >> >> (let [me {:person {:name {:first "Mark" >> :last "Triggs"} >> :email "mark.h.tri...@gmail.com"}}] >> (-> me :person :name :first)) >> >> => "Mark" >> >> On Jan 12, 1:04 pm, kkw <kevin.k....@gmail.com> wrote: >>> One use I've found for -> (though there are others I haven't come to >>> appreciate yet) is when I have something like: >>> (f1 (f2 (f3 (f4 x)))) >>> >>> which can be re-written as >>> (-> x f4 f3 f2 f1) >>> >>> I find the latter expression easier to read. >>> >>> Kev >>> >>> On Dec 30 2008, 2:49 pm, wubbie <sunj...@gmail.com> wrote: >>> >>> > Very criptic for newbie. >>> > What does "Threads the expr through the forms." mean? >>> > Does it create a thread to execute? >>> >>> > thanks >>> > sun >>> >>> > On Dec 29, 10:07 pm, Paul Barry <pauljbar...@gmail.com> wrote: >>> >>> > > You can look up the documentation for a function/macro interactively >>> > > from the repl: >>> >>> > > user=> (doc ->) >>> > > ------------------------- >>> > > clojure.core/-> >>> > > ([x form] [x form & more]) >>> > > Macro >>> > > Threads the expr through the forms. Inserts x as the >>> > > second item in the first form, making a list of it if it is not a >>> > > list already. If there are more forms, inserts the first form as the >>> > > second item in second form, etc. >>> > > nil >>> >>> > > On Dec 29, 8:27 pm, wubbie <sunj...@gmail.com> wrote: >>> >>> > > > Hi all, >>> >>> > > > Looking intoants.clj, I came across >>> > > > (defn place [[x y]] >>> > > > (-> world (nth x) (nth y))) >>> >>> > > > What -> mean here? >>> >>> > > > thanks >>> > > > sun > > I initially stumbled on what -> is good for. But over time it makes > more sense. I like to think of it as similar to this construct, which > you often see in the Java world: > > Object result = object.doSomething().doSomethingElse().andMoreThings(); > > Of course the doSomethings could also be get*s() or what-have-you.
While we're on this topic, don't forget the closely related doto function which calls many functions on the same object, unlike -> which calls many functions on the result of the previous function. Here's the example from the doc string. (doto (new java.util.HashMap) (.put "a" 1) (.put "b" 2)) -- R. Mark Volkmann Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---