是否有内置函数可以打印没有顶级括号的列表项,或者是否有更好的编写方法
(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
答案 0 :(得分:17)
这样的东西?
(apply println '(1 2 3 4 5))
1 2 3 4 5
nil
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.
答案 1 :(得分:3)
在clojure-contrib.string中你有函数join,
user=> (require '[clojure.contrib.string :as string])
nil
user=> (string/join " " '(1 2 3 4 4))
"1 2 3 4 4"
user=> (println (string/join " " '(1 2 3 4 4)))
1 2 3 4 4
nil