(ns e2-44-45
  (:use clojure.test))
(defn beside [a b] nil)
(defn below [a b] nil)
(defn up-split [painter n]
  (if (= n 0)
    (let [smaller (up-split painter (dec n))]
      (below painter (beside smaller smaller)))))

(defn right-split (split beside below)) (defn up-split (split below beside))

Lets note that the only thing different between the right and up splits is the last line:

  • right-split: (beside (below m m) painter))))
  • up-split: (below (beside m m) painter))))

Which means that we need to return a function which takes a painter and an n. Inside of that function we need to use the arguments (in lexical scope) to the split function.

(defn split [f g]
  (fn [painter n]
    (if (= n 0)
      (let [m ((split f g) painter (dec n))]
        (f (g m m) painter)))))