0

i have one file "map_reduce2.clj" and another "map_reduce3.clj", the both defin function "map-reduce" themself.

now i want to use namespace of "map_reduce2.clj" in "map_reduce3.clj", but when i press "C-c C-k" in emacs to compile the "map_reduce3.clj",

error happens: "parse-line already refers to: #'chapter12.map-reduce2/parse-line in namespace: chapter12.map-reduce3" , but this doesn't make any sense.

; 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))))

images of the the error

1 Answer 1

2

This probably means you have dirty REPL state. Maybe you moved the function parse-line from one namespace to the other. I suggest restarting the REPL, or unload parse-line from map-reduce3: How to unload a function from another namespace?.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.