Interesting. The result of (format "'%-9s'" "12345") displays as "'12345 '" - " added by LT. Yet (count (format "'%-9s'" "12345")) returns 11, as you say, which is correct.
Am I looking at a LightTable bug then? On Sunday, 6 April 2014 13:42:40 UTC-6, Andy Fingerhut wrote: > > Paul, can you double-check the result you are getting from (format > "'%-9s'" "12345") ? > > For example, wrap it in a call to count, i.e. (count (format "'%-9s'" > "12345")). I get the expected string back from format, and the expected > length of 11 characters, on all of these Clojure/JVM/OS combos I tested: > > Mac OS X 10.8.5 + JVM 1.7.0_51 + Clojure 1.5.1 > Mac OS X 10.8.5 + JVM 1.7.0_51 + Clojure 1.6.0 > Ubuntu Linux 12.04.4 + OpenJDK 1.6.0_30 + Clojure 1.5.1 > > If you are still getting incorrect results, what combination of software > versions are you using? > > Andy > > > > On Sun, Apr 6, 2014 at 12:27 PM, Paul Umbers <[email protected]<javascript:> > > wrote: > >> I'm trying to right-pad a string up to 9 characters, for example "12345" >> should become "12345 ", and the only idea I've come up with so far is to >> use clojure.core/format which states: "Formats a string using >> java.lang.String.format, see java.util.Formatter for format string syntax >> ". However, there seems to be a discrepancy in what the Clojure format >> function returns compared with the Java formatter. >> >> In Java, new Formatter().format("'%-9s'", "12345") correctly returns '12345 >> ' - the ' are there for legibility. String.format("'%-9s'", "12345")also >> returns the correctly padded string. >> >> However, in Clojure (format "'%-9s'" "12345") returns '12345 ' - it has >> only padded the string by 1 space, and not 4 as with the Java version. >> >> Also, (String/format "'%-9s'" (to-array "12345")) - taken from the >> clojure.core/format source and substituting parameters directly- returns '1 >> ', and (String/format "'%-9s'" (to-array '(\1 \2 \3 \4 \5)))returns >> '1 >> '. >> >> The one thing that works correctly is (String/format "'%-9s'" (to-array >> ["12345"])) which returns '12345 '. >> >> I'm not really clear on what's going wrong here, but clojure.core/format >> doesn't appear to be working as described - at least for a single string >> argument. >> >> I'll continue to investigate, but if anyone can offer some comments to >> help? ... >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to [email protected]<javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> [email protected] <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
