gpt4 book ai didi

Clojure 打印不带括号的列表?

转载 作者:行者123 更新时间:2023-12-04 01:40:22 24 4
gpt4 key购买 nike

是否有内置函数来打印没有顶级括号的列表项,或者是否有更好的编写方法

(defn println-list
"Prints a list without top-level parentheses, with a newline at the end"
[alist]
(doseq [item alist]
(print (str item " ")))
(print "\n"))

得到输出
user=> (println-list '(1 2 3 4))
1 2 3 4
nil

最佳答案

像这样的东西?

(apply println '(1 2 3 4 5))
1 2 3 4 5
nil

来自 Clojure docs for apply :
Usage: (apply f args)
(apply f x args)
(apply f x y args)
(apply f x y z args)
(apply f a b c d & args)
Applies fn f to the argument list formed by prepending intervening
arguments to args.

关于Clojure 打印不带括号的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8650071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com