|
|
|
|
|
by jhickner
5111 days ago
|
|
shiffern's example uses the same coding style you use in Clojure. It doesn't feel like stretch to call it FP. Start with a basic data structure (the object in shiffern's example would translate to a map in Clojure) and then operate on it with simple functions. (def snake {:name "Sammy"
:distance 5
:move-verb "Slither"})
(def horse {:name "Tommy"
:distance 45
:move-verb "Gallop"})
(defn move[{:keys [name distance move-verb]}]
(println (str (or move-verb "Mov") "ing..."))
(println (or name "It") "moved" (or distance 1) "meters"))
(move snake)
(move horse)
|
|