Skip to content

Instantly share code, notes, and snippets.

Created July 15, 2011 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1085665 to your computer and use it in GitHub Desktop.
Save anonymous/1085665 to your computer and use it in GitHub Desktop.
(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