From 7b68206577ddf8c5d9fc83c8eec09207b2174791 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 22 Jan 2023 18:50:38 +0000 Subject: [PATCH] make turn-left/right return mergable tables this gives greater symmetry with `drive` --- rover.fnl | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/rover.fnl b/rover.fnl index 436541c..91c7810 100644 --- 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]