Is there a built-in function to print the items of a list without top-level parentheses, or would there be a better way to write
(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"))
to get an output of
user=> (println-list '(1 2 3 4))
1 2 3 4
nil
Something like this?
(apply println '(1 2 3 4 5))
1 2 3 4 5
nil
From the 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.
in clojure-contrib.string you have the function 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With