2009-06-24 5 views
5

명확한 레퍼런스 벡터를 만드는 가장 간단한 방법은 무엇입니까?Clojure 레퍼런스 벡터

목록을 반환합니다 (repeat 5 (ref nil))를 사용하지만, 그들은 모두 같은 심판 참조합니다 :

user=> (repeat 5 (ref nil)) 
(#<[email protected]: nil> #<[email protected]: nil> #<[email protected]: nil> #<[email protected]: nil> #<R 
[email protected]: nil>) 

같은 결과 (replicate 5 (ref nil))과를 :

user=> (replicate 5 (ref nil)) 
(#<[email protected]: nil> #<[email protected]: nil> #<[email protected]: nil> #<[email protected]: nil> 
#<[email protected]: nil>) 

답변

4

좋아,이 꽤 심한이지만, 작동 : 당신은/원하는 경우 필요하며,이 LazySeq을 반환

user=> (map (fn [_] (ref nil)) (range 5)) 
(#<[email protected]: nil> #<[email protected]: nil> #<[email protected]: nil> #<[email protected]: nil> #<[email protected]: nil>) 

벡터, 그럼 그냥 사용 후

user=> (vec (map (fn [_] (ref nil)) (range 5))) 
[#<[email protected]: nil> #<[email protected]: nil> #<[email protected]: nil> #<[email protected]: nil> #<[email protected]: nil>]