Re: Exercise: words frequency ranking

2009-01-03 Thread Emeka
Venlig hilsen and Timothy Prately Thanks so much. Emeka --~--~-~--~~~---~--~~ 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,

Re: Exercise: words frequency ranking

2009-01-03 Thread Christian Vest Hansen
Hehe, venlig hilsen is danish for kind regards :) On Sat, Jan 3, 2009 at 3:23 PM, Emeka emekami...@gmail.com wrote: Venlig hilsen and Timothy Prately Thanks so much. Emeka -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~

Re: Exercise: words frequency ranking

2009-01-03 Thread Emeka
Thanks. I have learnt some new. Emeka --~--~-~--~~~---~--~~ 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

Re: Exercise: words frequency ranking

2008-12-29 Thread Timothy Pratley
You could consider using a StreamTokenizer: (import '(java.io StreamTokenizer BufferedReader FileReader)) (defn wordfreq [filename] (with-local-vars [words {}] (let [st (StreamTokenizer. (BufferedReader. (FileReader. filename)))] (loop [tt (.nextToken st)] (when (not= tt

Re: Exercise: words frequency ranking

2008-12-29 Thread Emeka
Hello sir, I would have asked this question in the thread but , I don't want to create noise over this issue. I have not been able to get my head around your code or Clojure. I need some support. (defn top-words-core [s] (reduce #(assoc %1 %2 (inc (%1 %2 0))) {} (re-seq #\w+

Re: Exercise: words frequency ranking

2008-12-29 Thread Timothy Pratley
(defn top-words-core [s]      (reduce #(assoc %1 %2 (inc (%1 %2 0))) {}              (re-seq #\w+                      (.toLowerCase s maps are functions of their keys means: user= ({:a 1, :b 2, :c 3} :a) 1 Here we created a map {:a 1, :b 2, :c 3}, can then called it like a function with

Re: Exercise: words frequency ranking

2008-12-28 Thread Boyd Brown
Hello. I can't seem to find 'spit'. java exception: unable to resolve symbol spit. I'm using Clojure Box rev1142. Tried using the clojure.jar from the 20081217 release of Clojure but to no avail. spit is not documented on the clojure site API page like slurp is. I can't find it in clojure

Where's spit? (Was: Exercise: words frequency ranking)

2008-12-28 Thread Mibu
You're not at fault here. The documentation about loading libraries is still scarce and not very helpful yet. I too had to scramble to figure this one out. spit is in the duck-streams library in clojure.contrib. I understand it is planned to be moved to the core library, as it should. Here is

Re: Where's spit? (Was: Exercise: words frequency ranking)

2008-12-28 Thread Boyd Brown
On Dec 28, 9:33 am, Mibu mibu.cloj...@gmail.com wrote: You're not at fault here. The documentation about loading libraries is still scarce and not very helpful yet. I too had to scramble to figure this one out. spit is in the duck-streams library in clojure.contrib. I understand it is

Re: Exercise: words frequency ranking

2008-12-28 Thread Chouser
On Sun, Dec 28, 2008 at 9:22 AM, Boyd Brown boy...@gmail.com wrote: Hello. I can't seem to find 'spit'. 'spit' is in clojure-contrib: http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/duck_streams.clj?r=325#177 It's inclusion in clojure.core is planned (search

Re: Exercise: words frequency ranking

2008-12-27 Thread Piotr 'Qertoip' Włodarek
Thank you for all improvements and suggestions. Based on your feedback, here is my final version: (defn read-words Given a file, return a seq of every word in the file, normalizing words by coverting them to lower case and splitting on whitespace [in-filepath] (re-seq #\w+

Re: Exercise: words frequency ranking

2008-12-27 Thread Piotr 'Qertoip' Włodarek
And the nice pastie version: http://pastie.org/347369 regards, Piotrek --~--~-~--~~~---~--~~ 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

Re: Exercise: words frequency ranking

2008-12-26 Thread lpetit
Instead of #(- (val %)), one could also use the compose function : (comp - val) My 0,02 EURO, -- Laurent On Dec 25, 4:58 pm, Mibu mibu.cloj...@gmail.com wrote: My version: (defn top-words [input-filename result-filename] (spit result-filename (apply str (map

Re: Exercise: words frequency ranking

2008-12-26 Thread lpetit
What would you think of this form of coding ? - The rationale is to separate functions that deal with system boundaries from core algorithmic functions. So you should at least have two functions : one that does not deal with input/output formats : will only deal with clojure/java constructs. -

Re: Exercise: words frequency ranking

2008-12-26 Thread Piotr 'Qertoip' Włodarek
On Dec 25, 4:58 pm, Mibu mibu.cloj...@gmail.com wrote: My version: (defn top-words [input-filename result-filename]   (spit result-filename         (apply str                (map #(format %s : %d\n (first %) (second %))                     (sort-by #(-(val %))                              

Exercise: words frequency ranking

2008-12-25 Thread Piotr 'Qertoip' Włodarek
Given the input text file, the program should write to disk a ranking of words sorted by frequency, like: the : 52483 and : 32558 of : 23477 a : 22486 to : 21993 My first implementation: (defn topwords

Re: Exercise: words frequency ranking

2008-12-25 Thread Mibu
My version: (defn top-words [input-filename result-filename] (spit result-filename (apply str (map #(format %s : %d\n (first %) (second %)) (sort-by #(-(val %)) (reduce #(conj %1 { %2 (inc (%1 %2 0)) }) {}

Re: Exercise: words frequency ranking

2008-12-25 Thread Meikel Brandmeyer
Hi, Am 25.12.2008 um 17:24 schrieb wwmorgan: A better implementation would split the different steps of the program into separate functions. This increases readability and testability of the source code, and encourages the reuse of code in new programs. Yes. One can think of the data flowing