3 ms·
Pattern matching would be nice, but destructuring helps. (defn sum-acc ([xs] (sum-acc xs 0)) ([[x & xs] acc] (if (nil? x) acc
by ajuc 13y ago
Pattern matching would be nice, but destructuring helps.
(defn sum-acc
([xs] (sum-acc xs 0))
([[x & xs] acc]
(if (nil? x)
acc
(recur xs (+ x acc)))))
Could you show Haskell equivalent?
BTW there should be a macro that adds argument with default value.
- malisper 13y agoI believe it should be something along the lines of: sumacc xs = summer xs 0 where summer [] n = n summer (x:xs) n = summer xs (x+n) I'm sure there are macros in some library somewhere that implement pattern matching in lisp (regardless of dialect).