Clojure Vector of Refs
clojure, ref, vector
Solution
user> (doc repeatedly)
-------------------------
clojure.core/repeatedly
([f])
Takes a function of no args, presumably with side effects, and returns an infinite
lazy sequence of calls to it
nil
user> (take 5 (repeatedly #(ref nil)))
(#<Ref@1f10a67: nil> #<Ref@1e2161d: nil> #<Ref@1a034d: nil> #<Ref@1cee792: nil> #<Ref@c5577c: nil>)
us
Problem
What's the simplest way to create a vector of distinct refs? Using `(repeat 5 (ref nil))` will return a list, but they will all reference the same ref: ``` user=> (repeat 5 (ref nil)) (#<Ref@16ef71: nil> #<Ref@16ef71: nil> #<Ref@16ef71: nil> #<Ref@16ef71: nil> #<R ef@16ef71: nil>) ``` Same result with `(replicate 5 (ref nil))`: ``` user=> (replicate 5 (ref nil)) (#<Ref@1d88db7: nil> #<Ref@1d88db7: nil> #<Ref@1d88db7: nil> #<Ref@1d88db7: nil> #<Ref@1d88db7: nil>) ```