Skip to content

Instantly share code, notes, and snippets.

@olabini
Created November 20, 2009 02:06
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 olabini/239224 to your computer and use it in GitHub Desktop.
Save olabini/239224 to your computer and use it in GitHub Desktop.
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