make turn-left/right return mergable tables

this gives greater symmetry with `drive`
main
Daniel Barlow 2023-01-22 18:50:38 +00:00
parent 13e283a2a5
commit 7b68206577
1 changed files with 18 additions and 16 deletions

View File

@ -21,30 +21,32 @@
:e {:x (+ x distance)}))
(fn turn-left [direction]
(-> {
:n :w
:w :s
:s :e
:e :n
}
(. direction)))
{:direction
(-> {
:n :w
:w :s
:s :e
:e :n
}
(. direction))})
(fn turn-right [direction]
(-> {
:n :e
:e :s
:s :w
:w :n
}
(. direction)))
{:direction
(-> {
:n :e
:e :s
:s :w
:w :n
}
(. direction))})
(fn command [rover string]
(merge rover
(match string
:f (drive rover 1)
:b (drive rover -1)
:r {:direction (turn-right rover.direction)}
:l {:direction (turn-left rover.direction)}
:r (turn-right rover.direction)
:l (turn-left rover.direction)
_ (assert false (. "unrecognised command " string)))))
(fn execute [rover cmds]