make turn-left/right return mergable tables
this gives greater symmetry with `drive`
This commit is contained in:
parent
13e283a2a5
commit
7b68206577
34
rover.fnl
34
rover.fnl
@ -21,30 +21,32 @@
|
|||||||
:e {:x (+ x distance)}))
|
:e {:x (+ x distance)}))
|
||||||
|
|
||||||
(fn turn-left [direction]
|
(fn turn-left [direction]
|
||||||
(-> {
|
{:direction
|
||||||
:n :w
|
(-> {
|
||||||
:w :s
|
:n :w
|
||||||
:s :e
|
:w :s
|
||||||
:e :n
|
:s :e
|
||||||
}
|
:e :n
|
||||||
(. direction)))
|
}
|
||||||
|
(. direction))})
|
||||||
|
|
||||||
(fn turn-right [direction]
|
(fn turn-right [direction]
|
||||||
(-> {
|
{:direction
|
||||||
:n :e
|
(-> {
|
||||||
:e :s
|
:n :e
|
||||||
:s :w
|
:e :s
|
||||||
:w :n
|
:s :w
|
||||||
}
|
:w :n
|
||||||
(. direction)))
|
}
|
||||||
|
(. direction))})
|
||||||
|
|
||||||
(fn command [rover string]
|
(fn command [rover string]
|
||||||
(merge rover
|
(merge rover
|
||||||
(match string
|
(match string
|
||||||
:f (drive rover 1)
|
:f (drive rover 1)
|
||||||
:b (drive rover -1)
|
:b (drive rover -1)
|
||||||
:r {:direction (turn-right rover.direction)}
|
:r (turn-right rover.direction)
|
||||||
:l {:direction (turn-left rover.direction)}
|
:l (turn-left rover.direction)
|
||||||
_ (assert false (. "unrecognised command " string)))))
|
_ (assert false (. "unrecognised command " string)))))
|
||||||
|
|
||||||
(fn execute [rover cmds]
|
(fn execute [rover cmds]
|
||||||
|
Loading…
Reference in New Issue
Block a user