On Sun, Aug 2, 2009 at 5:48 AM, James Sofra <james.so...@gmail.com> wrote:
> (defn tile-in-bounds? [[x y] maze] > (let [h (count maze)] > (if (and (>= y 0) (>= x 0) (< y h)) > (if (< x (count (maze y))) > true)))) (defn tile-in-bounds? [[x y] maze] (and (>= y 0) (>= x 0) (< y (count maze)) (< x (count (maze y))))) Since "and" short-circuits, it's safe to have "(maze y)" after "(< y (count maze))". (defn get-tile [[x y] maze] > (if (tile-in-bounds? [x y] maze) > ((maze y) x))) (defn get-tile [[x y] maze] (get (get maze y) x)) This has identical results (including nil for out-of-bounds). (defn update-tile [[x y] maze value] > (if (tile-in-bounds? [x y] maze) > (assoc maze y (assoc (maze y) x value)) > maze)) Might simplify this a bit using assoc-in. > (defn filter-neighbours [f [x y] maze] > (for [dir (list [0 -1] [1 0] [0 1] [-1 0]) > :when (f (map + [x y] dir) maze)] > (map + [x y] dir))) (defn filter-neighbors [f [x y] maze] (filter #(f % maze) (map #(map + [x y] %) (list [0 -1] [1 0] [0 1] [-1 0])))) Maybe that one's not simpler so much as just different. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---