我有一个文件“map_reduce2.clj”和另一个“map_reduce3.clj”,两个defin函数“map-reduce”自己。
现在我想在“map_reduce3.clj”中使用“map_reduce2.clj”的命名空间,但是当我在emacs中按“C-c C-k”来编译“map_reduce3.clj”时,
错误发生:“解析行已经引用:#'chapter12.map-reduce2 / parse-line in namespace:chapter12.map-reduce3“,但这没有任何意义。
; map_reduce3.cli
(ns chapter12.map-reduce3
(:use clojure.java.io)
(:require [chapter12.map-reduce2 :as c12]))
(def IGNORE "_")
(defn parse-line [line]
(let [tokens (.split (.toLowerCase line) " ")]
[[IGNORE (count tokens)]]))
(defn average [numbers]
(/ (apply + numbers)
(count numbers)))
(defn reducer [combined]
(average (val (first combined))))
(defn average-line-length [filename]
(c12/map-reduce parse-line reducer (line-seq (reader filename))))
; map_reduce2.clj
(ns chapter12.map-reduce2
(:use clojure.java.io))
(defn combine [mapped]
(->> (apply concat mapped)
(group-by first)
(map (fn [[k v]]
{k (map second v)}))
(apply merge-with conj)))
(defn map-reduce [mapper reducer args-seq]
(->> (map mapper args-seq)
(combine)
(reducer)))
(defn parse-line [line]
(let [tokens (.split (.toLowerCase line) " ")]
(map #(vector % 1) tokens)))
(defn sum [[k v]]
{k (apply + v)})
(defn reduce-parsed-lines [collected-values]
(apply merge (map sum collected-values)))
(defn word-frequency [filename]
(map-reduce parse-line reduce-parsed-lines (line-seq (reader filename))))
答案 0 :(得分:2)
这可能意味着您有脏REPL状态。也许你将函数parse-line
从一个名称空间移动到另一个名称空间。我建议重新启动REPL,或从parse-line
How to unload a function from another namespace?卸载map-reduce3
。