Created
July 29, 2014 12:28
-
-
Save plexus/2556baef03cb50e228bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bearings = { | |
north: ->(x,y) { [x+1, y] }, | |
east: ->(x,y) { [x, y+1] }, | |
south: ->(x,y) { [x-1, y] }, | |
west: ->(x,y) { [x, y-1] } | |
} | |
bot = ->(x, y, bearing) do | |
{ | |
coords: [x, y], | |
bearing: bearing, | |
step: -> do | |
bot.(*bearings[bearing].(x,y), bearing) | |
end | |
} | |
end | |
b = bot.(5, 5, :east) # => {:coords=>[5, 5], :bearing=>:east, :step=>#<Proc:0x00000001cffe58@-:12 (lambda)>} | |
b = b[:step].() # => {:coords=>[5, 6], :bearing=>:east, :step=>#<Proc:0x00000001cff7f0@-:12 (lambda)>} | |
b = b[:step].() # => {:coords=>[5, 7], :bearing=>:east, :step=>#<Proc:0x00000001cff250@-:12 (lambda)>} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment