Clojure
user=> (defn words [text] (re-seq #"[a-z]+" (. text (toLowerCase))))
#<Var: user/words>
user=> (defn train [features]
(reduce (fn [model f] (assoc model f (inc (get model f 1))))
{} features))
#<Var: user/train>
user=> (def *nwords* (train (words (slurp "/tmp/big.txt"))))
java.lang.OutOfMemoryError: Java heap space
at clojure.lang.PersistentHashMap$FullNode.assoc(PersistentHashMap.java:244)
at clojure.lang.PersistentHashMap.assoc(PersistentHashMap.java:105)
at clojure.lang.PersistentHashMap.assoc(PersistentHashMap.java:28)
at clojure.lang.RT.assoc(RT.java:467)
at clojure.fn__45.invoke(boot.clj:113)
at user.fn__960$fn__961.invoke(Unknown Source)
at clojure.fn__120.invoke(boot.clj:399)
at user.fn__960.invoke(Unknown Source)
at clojure.lang.AFn.applyToHelper(AFn.java:173)
at clojure.lang.AFn.applyTo(AFn.java:164)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2249)
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:257)
at clojure.lang.Compiler.eval(Compiler.java:3208)
at clojure.lang.Repl.main(Repl.java:64)
user=>