Re: Feedback on idiomatic clojure

2010-08-20 Thread Btsai
I believe duck-streams is deprecated since clojure 1.2. You may want to consider bringing back f-to-seq, which can be simplified slightly using reader from clojure.java.io: (ns clojure.example.anagrams (:use [clojure.java.io :only (reader)]) (:gen-class)) (defn f-to-seq [file] (with-open [

Re: Feedback on idiomatic clojure

2010-08-19 Thread Damon Snyder
Hi Meikel, Nicolas, and Justin, Thank you for the great feedback! I learned a lot. I was puzzled about (update-in (update-in)) and after doing that the -> operator makes a lot of sense. The reduce is clever and fits nicely as well. I dropped the function that read in the lines of the file and used

Re: Feedback on idiomatic clojure

2010-08-19 Thread Meikel Brandmeyer
Hi. Am 19.08.2010 um 22:14 schrieb Nicolas Oury: >> in because I was getting null pointer exceptions when the string was >> null. What is the difference between {:count 1 :words (list words)} >> and a hash-map? I was under the impression that {} created a hash. >> > I just find it easier to read

Fwd: Feedback on idiomatic clojure

2010-08-19 Thread Nicolas Oury
Damon reply to me and not the list, so I forward. On Thu, Aug 19, 2010 at 9:09 PM, Damon Snyder wrote: > Hi Nicolas, > Thanks for the suggestions. Regarding the first one: ah, I see. That > is a nice compact way to test to see if the str is nil. I added that I reckon that Meikel's suggestion of

Re: Feedback on idiomatic clojure

2010-08-19 Thread Justin Kramer
Meikel's suggestions are all good and I would follow them. There are a number of built-in functions you can take advantage of if you're using 1.2 (they're also available in contrib for 1.1): clojure.string/lower-case clojure.java.io/reader -- obviates java.io.BufferedReader and friends: (reader "

Re: Feedback on idiomatic clojure

2010-08-19 Thread Meikel Brandmeyer
Hi, here my turn. Comments inline. Hope this helps. Sincerely Meikel (defn f-to-seq [file] (with-open [rdr (java.io.BufferedReader. (java.io.FileReader. file))] (doall (line-seq rdr ; Yes. doall is required here. Alternatively you can wrap the whole thing ; in the

Re: Feedback on idiomatic clojure

2010-08-19 Thread Nicolas Oury
A few remarks: > > ## begin > (defn f-to-seq[file] >  (with-open [rdr (java.io.BufferedReader. >                    (java.io.FileReader. file))] >    (doall (line-seq rdr > Do you need the doall? > (defn str-sort[str] >  (if (nil? str) >    str >  (String. (into-array (. Character TYPE) (sort

Feedback on idiomatic clojure

2010-08-19 Thread Damon Snyder
Hi Everyone, I'm looking for some feedback on a small get-your-feet wet program I wrote in clojure (my first). In particular, I hope to get feedback on how to better make use of clojure's data structures and functional programming in general. Below is the toy program and the sample output. It read