Skip to content

Instantly share code, notes, and snippets.

@AlexBaranosky
Created November 23, 2013 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexBaranosky/7621419 to your computer and use it in GitHub Desktop.
Save AlexBaranosky/7621419 to your computer and use it in GitHub Desktop.
varargs + recur
;; Could do this
(defn add* [[x & more] total]
(if-not x
total
(recur more (+ x total ))))
(defn add1 [& xs]
(add* xs 0))
;; I'd do this
(defn add2 [& xs]
(loop [[x & more] xs
total 0]
(if-not x
total
(recur more (+ x total)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment