Skip to content

Instantly share code, notes, and snippets.

/gist:1085665
Created Jul 15, 2011

Embed
What would you like to do?
(ns robo-replacement.map-maker)
(defn worldmap-add
[worldmap x y]
(let [ykey (keyword (str y))
xkey (keyword (str x))]
(if (= y (count worldmap))
;;add the new x coord
(assoc worldmap ykey (assoc (ykey worldmap) xkey {})))))
(defn generate-map
;;default remapping to inner function call
([xmax ymax] (recur xmax ymax xmax ymax {}))
;;default inner function call
([xmax ymax xcur ycur worldmap]
(if (and (zero? ycur) (zero? xcur)) worldmap)
(if (zero? xcur)
(recur xmax ymax xmax (dec ycur) (worldmap-add worldmap xcur ycur))
(recur xmax ymax (dec xcur) ycur (worldmap-add worldmap xcur ycur)))))
(defn map-maker
[] (generate-map 10 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.