extract function "command"

main
Daniel Barlow 2023-01-22 17:54:03 +00:00
parent 3375906dee
commit f8a58c4a68
1 changed files with 9 additions and 6 deletions

View File

@ -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)))