模式 / 行为模式
image

;; Strategy folds into a plain function passed to the context:
;; no Strategy interface, no ConcreteStrategy classes

;; Context — takes the strategy as an argument
(defn calc [strategy a b]
  (if strategy (strategy a b) 0))

(println (calc nil 5 3))  ; 0 — no strategy set
(println (calc + 5 3))    ; 8 — the "add" strategy is just +
(println (calc - 5 3))    ; 2 — and the "subtract" one is -

;; A strategy can be written on the spot as well
(println (calc #(* %1 %25 3))  ; 15