Hi, On Sun, Sep 13, 2009 at 1:23 AM, Terrance Davis <terrance.da...@gmail.com>wrote:
> > I translate this into Clojure as something like ... > > (def final-foo > (. Double parseDouble > (. javax.swing.JOptionPane showInputDialog "What is your foobar?"))) > > While not directly related: try to not use the . (dot) operator. Use (Foo/staticMethod ...) or (.method obj ...) instead. (ditto for (new Foo ...) vs (Foo. ...)) (def final-foo (Double/parseDouble (javax.swing.JOptionPane/showInputDialog "What is your foobar?"))) When you have nested calls on the first arg, you can flatten them using -> : (def final-foo (-> (javax.swing.JOptionPane/showInputDialog "What is your foobar?") Double/parseDouble)) You can even write: (def final-foo (-> "What is your foobar?" javax.swing.JOptionPane/showInputDialog Double/parseDouble)) but I'm unsure we gain in readability this time. -> proves also to be suseful when you are piling constructors: (java.io.BufferedReader. (java.io.InputStreamReader. an-input-stream "UTF-8")) can be rewritten: (-> an-input-stream (java.io.InputStreamReader. "UTF-8") java.io.BufferedReader.) HTH, Christophe --~--~---------~--~----~------------~-------~--~----~ 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 Note that posts from new members are moderated - please be patient with your first post. 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 -~----------~----~----~----~------~----~------~--~---