Thanks Jason.
Anyway I'd like to have (sum) returns 0 so I used [& more].
Is there any way to specify 0 or more args?

-sun


On Jan 23, 12:49 pm, Jason Wolfe <jawo...@berkeley.edu> wrote:
> Two mistakes:
>
> First, if you want sum to take a vector, you should remove the & from
> the arglist.
> Second, (rest(other)) should be (rest other).
>
> This buys you:
>
> user> (defn sum [more ]
>         ((fn [total other]
>            (if other
>                (recur (+ total (first other)) (rest other))
>              total))
>          0 more))
> #'user/sum
> user> (sum [1 2 3 4])
> 10
>
> (of course, sum could also be defined as just (apply + more) or
> (reduce + more)).
>
> -Jason
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to