On Mon, Feb 2, 2009 at 6:34 AM, wubbie <sunj...@gmail.com> wrote: > > any concrete example?
Here's an example of how -> makes it easy to get data out of nested maps. (def person { :name "Mark Volkmann" :address { :street "644 Glen Summit" :city "St. Charles" :state "Missouri" :zip 63304} :employer { :name "Object Computing, Inc." :address { :street "12140 Woodcrest Executive Drive, Suite 250" :city "Creve Coeur" :state "Missouri" :zip 63141}}}) (-> person :employer :address :city) ; returns "Creve Coeur" Here's an example of how using doto with Swing is handy. (ns com.ociweb.swing (:import (java.awt BorderLayout) (java.awt.event ActionListener) (javax.swing JButton JFrame JLabel JOptionPane JPanel JTextField))) (defn message [text-field] (str "Hello, " (.getText text-field) "!")) (let [name-field (JTextField. "World" 10) panel (JPanel.) greet-button (JButton. "Greet") frame (proxy [JFrame ActionListener] [] ; superclass constructor arguments (actionPerformed [e] (JOptionPane/showMessageDialog nil (message name-field))))] (doto panel (.add (JLabel. "Name:")) (.add name-field)) (doto frame (.add panel BorderLayout/CENTER) (.add greet-button BorderLayout/SOUTH) (.pack) (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE) (.setVisible true)) (.addActionListener greet-button frame)) > On Feb 2, 5:13 am, Christian Vest Hansen <karmazi...@gmail.com> wrote: >> On Sun, Feb 1, 2009 at 9:35 PM, e <evier...@gmail.com> wrote: >> > This may be obvious to others, but what's the motivation behind it? Is it >> > that we are very concerned about combatting the criticism that lisp has too >> > many parens? >> >> The -> macro is simply an excellent tool for drilling into nested >> structures and/or piping some value through a list of methods and >> functions. >> >> It works very well indeed when mixed with doto - especially if you >> have to work with Swing or other component'ish frameworks. >> >> > On Sun, Feb 1, 2009 at 3:09 PM, kkw <kevin.k....@gmail.com> wrote: >> >> >> Hi sun, >> >> >> I thought this question looked familiar. I found some answers here >> >> also: >> >> >>http://groups.google.com/group/clojure/browse_thread/thread/1f21663ea... >> >> >> Kev >> >> >> On Feb 2, 2:29 am, Adrian Cuthbertson <adrian.cuthbert...@gmail.com> >> >> wrote: >> >> > Sorry! That should have read; >> >> > (-> m :one :b) >> >> > 2 >> >> >> > On Sun, Feb 1, 2009 at 5:13 PM, e <evier...@gmail.com> wrote: >> >> > > I was able to work through the first two examples, and thanks for >> >> > > those. I >> >> > > will have to study maps more, I guess, to understand the last one. I >> >> > > don't >> >> > > know where 'x' came from: >> >> >> > >> user=> (-> x :one :b) >> >> > >> 2- Hide quoted text - -- 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 -~----------~----~----~----~------~----~------~--~---