rover

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 7b68206577ddf8c5d9fc83c8eec09207b2174791
parent 13e283a2a592eba668773c4d58254076be7b41f0
Author: Daniel Barlow <dan@telent.net>
Date:   Sun, 22 Jan 2023 18:50:38 +0000

make turn-left/right return mergable tables

this gives greater symmetry with `drive`

Diffstat:
Mrover.fnl | 34++++++++++++++++++----------------
1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/rover.fnl b/rover.fnl @@ -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]