I really hate how GMail line wraps without giving you a chance to preview before sending.
Here's a version of parse that shouldn't line wrap. It also more closely parallels unparse by using for instead of map: (defn parse [file] (let [r (reader file)] (for [line (take (Integer/parseInt (.readLine r)) (repeatedly #(.readLine r)))] (map #(Integer/parseInt %) (.split line " "))))) -Per On Thu, Apr 22, 2010 at 10:29 PM, Per Vognsen <per.vogn...@gmail.com> wrote: > How about this? > > (use 'clojure.contrib.str-utils 'clojure.contrib.duck-streams) > > (defn parse [file] > (let [r (reader file)] > (map (fn [line] (map #(Integer/parseInt %) (.split line " "))) > (take (Integer/parseInt (.readLine r)) (repeatedly > #(.readLine r)))))) > > (defn unparse [xss file] > (let [w (writer file)] > (.writeLine w (str (count xss)) > (doseq [xs xss] > (.writeLine w (str-join " " (map str xs))))))) > > -Per > > On Thu, Apr 22, 2010 at 1:40 AM, I.K. <ignacykrasicki...@gmail.com> wrote: >> Hi! >> I'm learning Clojure and trying some Google Code Jam exercises. >> I am more or less satisfied with the style of algorithms I write, but >> I would like to know how to do input/output. I want it to be Clojure >> style (terse/functional/efficient) not just rewriting the usual >> loops... >> Take a look at simplest example from io standpoint: >> http://code.google.com/codejam/contest/dashboard?c=188266#. >> I want the file: >> >> 3 >> 2 3 >> 2 3 7 >> 9 10 >> >> turn into vector: [ [2 3] [2 3 7] [9 10] ], >> >> and in reverse direction (produce file given above from this vector). >> >> Show your style. >> >> Thanks, >> I.K. >> >> -- >> 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 > -- 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