On Nov 28, 1:05 am, "Michael Wood" <[EMAIL PROTECTED]> wrote: > On Fri, Nov 28, 2008 at 2:59 AM, Kei Suzuki <[EMAIL PROTECTED]> wrote: > > > On Nov 27, 11:21 am, Chouser <[EMAIL PROTECTED]> wrote: > [...] > >> All those methods take Java variadic arguments, which generally means > >> you need build the array the method is expecting. Fortunately, in the > >> cases you list you can just use the Clojure function 'format' which > >> does it for you: > > >> (.println System/out (format "%d" 1)) > [...] > > Got it. So these also work and are close to what I really wanted to > > do. > > > (.printf System/out Locale/US "%-10.4f\n" (to-array [Math/PI])) > > (.printf System/out Locale/FRANCE "%-10.4f\n" (to-array [Math/PI])) > > [...] > > I think Chouser's way of doing this looks less ugly: > > (.println System/out (format "%.4f" Math/PI)) > > I don't see a reasonable way to incorporate Locale/US etc. in there, though. > > Is there any way Clojure could automatically convert: > > (.printf System/out Locale/US "%-10.4f\n" Math/PI) > > to: > > (.printf System/out Locale/US "%-10.4f\n" (to-array [Math/PI])) > > because it's a method that takes variadic args? Or would it have to guess? > > -- > Michael Wood <[EMAIL PROTECTED]>
So I wrote the code attached and added it to my user.clj. It allows you to make the calls like these: user> (sprintf *out* "%s = %-10.4f\n" "pi" Math/PI) pi = 3.1416 nil user> (slprintf System/out java.util.Locale/FRANCE "%s = %-10.4f\n" "pi" Math/PI) pi = 3,1416 nil user> (sprintf *err* "Divided by %s error\n" (if (zero? 0) "zero" "NaN")) Divided by zero error nil I'd like to see the code merged in the core... -- Kei --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
printf-family-snippet.clj
Description: Binary data