可变参数函数是带有不同数量参数的函数(某些参数是可选的)。 函数也可以指定“&”符号以接受任意数量的参数。
(defn demo [message & others] (str message (clojure.string/join " " others)))
上面的函数声明在参数arother旁边有一个“&”符号,这意味着它可以接受任意数量的参数。
如果您将上述函数调用为
(demo "Hello" "This" "is" "the" "message")
以下将是输出。
链接:https://www.learnfk.comhttps://www.learnfk.com/clojure/clojure-variadic-functions.html
来源:LearnFk无涯教程网
“HelloThis is the message”
" clojure.string/join" 用于合并每个单独的字符串参数,该参数传递给函数。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)