Expand a vector into the arguments of a function

荒凉一梦 提交于 2019-12-18 04:30:06

问题


Is there a way to expand a vector of values into the arguments of a function? e.g. something like this:

(defn addnums [a b]
  (apply + (flatten [a b])))

(def args [[1 2 3] [1 2 3]])

(addnums *args)

回答1:


You can just use apply again:

(apply addnums args)


来源:https://stackoverflow.com/questions/3849084/expand-a-vector-into-the-arguments-of-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!