The function returns a map with the keys being word pairs and the value being a single word. It is a component of a larger program.
user=> (generate-chain "a quick brown fox jumps over the lazy dog") {("the" "lazy") ("dog"), ("over" "the") ("lazy"), ("jumps" "over") ("the"), ("fox" "jumps") ("over"), ("brown" "fox") ("jumps"), ("quick" "brown") ("fox"), ("a" "quick") ("brown")} As you said, there are definitely more efficient ways of doing this. Basically, this is my friends first stab at Clojure, and I was mainly trying to get to the bottom of why the overflow exception was happening. Could you elaborate on your suggestion of using lazy-seq some? I'm still a bit fuzzy on implementing my own lazy functions. Thanks, Travis On Sep 3, 2:08 am, Krukow <karl.kru...@gmail.com> wrote: > On Sep 2, 7:02 pm, tmountain <tinymount...@gmail.com> wrote: > > > (defn generate-chain [source] > > (loop [the-list (map #(list (first (split-at 2 %)) (last %)) > > (partition 3 1 (.split (.replace source "\n" " > > ") " "))) > > res (hash-map)] > > (if (empty? the-list) > > res > > (recur (filter #(not= (first (first the-list)) > > (first %)) the-list) > > (assoc res (first (first the-list)) > > (map #(last %) > > (filter #(= (first (first the-list)) > > (first %)) the-list))))))) > > > (println (generate-chain (slurp "big-file.txt"))) > > I having a bit of a hard time decoding what this function does. I get > that it is producing a Markov chain from a description in a file. Can > you describe the format of the file, and how you are representing the > output (i.e. the chain - is it a map representing the state-transition > matrix)? An example input/output would be fine. > > However, I suspect you can solve this by using lazy-seq and perhaps > preprocessing "the-list" into a more efficient data structure. > > /Karl --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---