clojurecademy / 4Clojure

4Clojure problems with a few differences
https://clojurecademy.com/courses/17592186045426/learn/overview
8 stars 2 forks source link

Problem 32/46 #36

Open beaverbrook opened 6 years ago

beaverbrook commented 6 years ago

I keep getting the exception, "clojure.lang.ArityException: Wrong number of args (0) passed to: core//"

I've isolated it to the second recur line. Is this a bug? Thanks.

(ns group-a-sequence)

(defn my-group-by [f s]
  (loop [x (rest s)
            acc {(f (first s)) [(first s)]}]
    (if (not (empty? x))
        (if (not (nil? (get acc (f (first x)))))
            (recur (rest x) (assoc acc (f (first x)) (conj (get acc (f (first x))) (first x))))

            ;*********************
            (recur (rest x) acc)) ; clojure.lang.ArityException: Wrong number of args (0) passed to: core//
            ;*********************

            ;(recur (rest x) (assoc acc (f (first x)) [(first x)])))
        ;acc)))
        3)))

(def s [[1 2] [2 4] [4 6] [3 6]])
(def f #(apply / %))

(my-group-by f s)