How to make a Clojure function take a variable number of parameters?

后端 未结 5 1618
闹比i
闹比i 2020-12-08 05:57

I\'m learning Clojure and I\'m trying to define a function that take a variable number of parameters (a variadic function) and sum them up (yep, just like the + pro

5条回答
  •  抹茶落季
    2020-12-08 06:25

    (defn sum [& args]
      (print "sum of" args ":" (apply + args)))
    

    This takes any number of arguments and add them up.

提交回复
热议问题