Created
November 20, 2009 02:06
-
-
Save olabini/239224 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
Position = Origin mimic do( | |
at = method(x, y, with(x: x, y: y)) | |
origin = at(0, 0) | |
+ = method(position, at(x + position x, y + position y)) | |
asText = method("(#{x},#{y})") | |
) | |
at = method(x, y, Position at(x,y)) | |
; This is pretty funny, right? | |
go = cell(:method) | |
Heading = Origin mimic do( | |
R = go(L L L) | |
asText = method(kind) | |
) | |
North = Heading with(L: go(West), rel: at(0, 1)) | |
East = Heading with(L: go(North), rel: at(1, 0)) | |
West = Heading with(L: go(South), rel: at(-1, 0)) | |
South = Heading with(L: go(East), rel: at(0, -1)) | |
Rover = Origin mimic do( | |
at = method(x, y, with(position: at(x, y))) | |
heading = method(dir, with(direction: dir)) | |
position = Position origin | |
direction = North | |
M = method(with(position: position + direction rel)) | |
L = go(heading(direction L)) | |
R = go(heading(direction R)) | |
asText = method("Rover @ #{position} #{direction}") | |
) | |
r1 = Rover at(1, 2) heading(North) | |
r1 L M L M L M L M M println | |
r2 = Rover at(3, 3) heading(East) | |
r2 M M R M M R M R R M println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment