Matchure: Serious Clojure Pattern Matching
spin.atomicobject.com
spin.atomicobject.com
(defn qsort
([] '())
([Head & Tail] (let [lower (filter #(< % Head) Tail)
upper (filter #(>= % Head) Tail)]
(concat (apply qsort lower) (list Head) (apply qsort upper)))))
I have barely played around with Clojure though, so if there is a nicer way to express that code, please drop a comment and try not to tear me to pieces. My point is that I would love to have pattern matching available in function definitions similar to Haskell/Erlang. (defn factorial
([0] 1)
([x] (* x (factorial (- x 1))))) (use 'matchure)
(defn-match factorial
([0] 1)
([?x] (* x (factorial (dec x)))))