diff --git a/rover.fnl b/rover.fnl index 82178fc..f60fd06 100644 --- a/rover.fnl +++ b/rover.fnl @@ -1,6 +1,7 @@ (local { : view } (require :fennel)) (local { : merge } (require :lume)) +;; who needs a test framework when you have lisp macros? (macro expect [text actual expected] `(let [actual# ,actual] (or (match actual# @@ -12,13 +13,15 @@ :actual actual# }))))) +(fn command [rover command] + (match rover.direction + :n (merge rover {:y (+ rover.y 1)}) + :s (merge rover {:y (- rover.y 1)}) + :w (merge rover {:x (- rover.x 1)}) + :e (merge rover {:x (+ rover.x 1)}))) + (fn execute [rover [cmd & cmds]] - (let [r1 - (match rover.direction - :n (merge rover {:y (+ rover.y 1)}) - :s (merge rover {:y (- rover.y 1)}) - :w (merge rover {:x (- rover.x 1)}) - :e (merge rover {:x (+ rover.x 1)}))] + (let [r1 (command rover)] (if (next cmds) (r1:execute cmds) r1)))