From 574c98236864f2b1e9c433ef88a342739d95bd85 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 22 Jan 2023 18:12:58 +0000 Subject: [PATCH] make execute a regular function not a method --- rover.fnl | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/rover.fnl b/rover.fnl index e4a06fc..42a2da7 100644 --- a/rover.fnl +++ b/rover.fnl @@ -46,14 +46,13 @@ (fn execute [rover [cmd & cmds]] (let [r1 (command rover cmd)] (if (next cmds) - (r1:execute cmds) + (execute r1 cmds) r1))) (fn rover [x y direction] {: x : y : direction - : execute }) (let [r (rover 7 15 :n)] @@ -64,41 +63,41 @@ (let [r (rover 0 0 :n)] (expect "The rover receives a character array of commands" - (r:execute [:f :f :f]) + (execute r [:f :f :f]) {})) (let [r (rover 0 0 :n)] (expect "Moves north when pointing north and asked to move forward" - (r:execute [:f]) {:x 0 :y 1 :direction :n})) + (execute r [:f]) {:x 0 :y 1 :direction :n})) (let [r (rover 3 2 :s)] (expect "Moves south when pointing south and asked to move forward" - (r:execute [:f]) {:x 3 :y 1 :direction :s})) + (execute r [:f]) {:x 3 :y 1 :direction :s})) (let [r (rover 0 0 :w)] (expect "Moves west when pointing west and asked to move forward" - (r:execute [:f]) {:x -1 :y 0 :direction :w})) + (execute r [:f]) {:x -1 :y 0 :direction :w})) (let [r (rover 0 0 :e)] (expect "Moves east when pointing east and asked to move forward" - (r:execute [:f]) {:x 1 :y 0 :direction :e})) + (execute r [:f]) {:x 1 :y 0 :direction :e})) (let [r (rover 1 1 :s)] (expect "The rover acts on multiple commands" - (r:execute [:f :f :f]) + (execute r [:f :f :f]) {:x 1 :y -2 :direction :s})) (let [r (rover 2 4 :e)] (expect "Rotates to south when pointing east and asked to turn right" - (r:execute [:r]) {:x 2 :y 4 :direction :s})) + (execute r [:r]) {:x 2 :y 4 :direction :s})) (let [r (rover 2 4 :s)] (expect "Rotates to east when pointing south and asked to turn left" - (r:execute [:l]) {:x 2 :y 4 :direction :e})) + (execute r [:l]) {:x 2 :y 4 :direction :e})) (let [r (rover 2 4 :w)] (expect "Rotates to north when pointing west and asked to turn right" - (r:execute [:r]) {:x 2 :y 4 :direction :n})) + (execute r [:r]) {:x 2 :y 4 :direction :n})) (print "OK")