Created
November 23, 2013 23:38
-
-
Save AlexBaranosky/7621419 to your computer and use it in GitHub Desktop.
varargs + recur
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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