Delegates are just closures right? Those are fun to work with:
(defn draw-map [g game-map player]
(.setColor g Color/WHITE)
(shadowcast
#(let [x (+ %1 (:x @player))
y (+ %2 (:y @player))]
(draw-tile g (@game-map x y) (+ %1 (/ console-tiles-x 2))
(+ %2 (/ console-tiles-y 2) (- 1))))
#(let [x (+ %1 (:x @player))
y (+ %2 (:y @player))]
(= :wall (:type (@game-map x y))))
(:sight-range @player)))
That's a piece of clojure code. Shadowcast is a function that does recursive shadow casting. It accepts 3 inputs: A function that is applied to each x/y coordinate in view, a function that tells it which x/y coordinates are blocked, and a value that tells it how far the player/creature/whatever can see. #(...) is clojure shorthand for make a function out of what's in between the parenthesis. %1...%n are the first... the nth input parameters respectively. Let introduces new local variables, which we need since the x and y provided by shadowcast are relative to the start position, so we need to translate them to map coordinates.
Now as you can see, we construct 2 functions that refer to variables present in this function, via (:x @player), (:y @player) and (@game-map x y). But those same variables are not present in the shadowcast function. So we've captured information about the current environment and passed it on to another environment (the shadowcast function). I could've put anything in there though. While testing I used #(println %1 %2), which just prints the provided x and y coordinates to the output. The shadowcast function only needs to do the shadowcasting, it doesn't need to know what we're doing with the coordinates, that's not it's job. I could use the same code to simulate light from a torch or the effect of an explosion.