extract common call to merge
This commit is contained in:
parent
94325e53a0
commit
db552b8c11
16
rover.fnl
16
rover.fnl
@ -31,17 +31,17 @@
|
|||||||
}
|
}
|
||||||
(. direction)))
|
(. direction)))
|
||||||
|
|
||||||
|
|
||||||
(fn command [rover string]
|
(fn command [rover string]
|
||||||
|
(merge rover
|
||||||
(match string
|
(match string
|
||||||
:f (match rover.direction
|
:f (match rover.direction
|
||||||
:n (merge rover {:y (+ rover.y 1)})
|
:n {:y (+ rover.y 1)}
|
||||||
:s (merge rover {:y (- rover.y 1)})
|
:s {:y (- rover.y 1)}
|
||||||
:w (merge rover {:x (- rover.x 1)})
|
:w {:x (- rover.x 1)}
|
||||||
:e (merge rover {:x (+ rover.x 1)}))
|
:e {:x (+ rover.x 1)})
|
||||||
:r (merge rover {:direction (turn-right rover.direction)})
|
:r {:direction (turn-right rover.direction)}
|
||||||
:l (merge rover {:direction (turn-left rover.direction)})
|
:l {:direction (turn-left rover.direction)}
|
||||||
_ (assert false (. "unrecognised command " string))))
|
_ (assert false (. "unrecognised command " string)))))
|
||||||
|
|
||||||
(fn execute [rover [cmd & cmds]]
|
(fn execute [rover [cmd & cmds]]
|
||||||
(let [r1 (command rover cmd)]
|
(let [r1 (command rover cmd)]
|
||||||
|
Loading…
Reference in New Issue
Block a user