On 22 Jul 2010, at 14:37, Rising_Phorce wrote:
I will need to traverse the vectors sequentially but at
each step there will be lots of sequential back and forward tracking.
Arrays would be the natural imperative choice, but the docs recommend
this only for inter-op. So are vectors the best choice?
Probably, but it's hard to say without knowing what exactly you need
to do on this data structure, and how often. Some other options are:
- a map from (x, y) coordinates to board values
- a vector of vectors of maps, with each map containg the board value
and references to neighbouring cells
Secondly, I figured out how to create a row (a vector of length
'size'): (defn make-row [size] (vec (take size (repeat nil))))
but I can't figure out how to conj 'size' calls to make-row onto
another empty vector.
Instead of (take size (repeat nil)), you can write (replicate size
nil). You can then make a square board filled with nils with
user> (defn square-board [size] (vec (replicate size (vec (replicate
size nil)))))
#'user/square-board
user> (square-board 3)
[[nil nil nil] [nil nil nil] [nil nil nil]]
Konrad.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en