2011-12-27 4 views

답변

16

의 출력을 얻을 수

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

를 작성하는 더 나은 방법이있을 것 이 같은? Clojure docs for apply에서

(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

에서, 당신은 함수가 합류 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 
관련 문제