2011-12-27 21 views

cevap

16

bir çıktısını almak için

(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")) 

yazmak için daha iyi bir yolu olurdu Böyle bir şey mi? Clojure docs for apply itibaren

(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. 
3

yılında, işlevin katılmak zorunda Clojure-contrib.string

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 
İlgili konular