On Oct 8, 8:35 am, CuppoJava <[EMAIL PROTECTED]> wrote:
> Hi,
> I'm very new to clojure, and I'm just wondering what's the most
> efficient way of creating a vector of zeroes.

This is one way.

user=> (vec (replicate 10 0))
[0 0 0 0 0 0 0 0 0 0]

also

user=> (into [] (replicate 10 0))
[0 0 0 0 0 0 0 0 0 0]

At the REPL you could use (doc <function_name>) to get help on the
function.
There are a bunch of these useful functions like repeat,
replicate, repeatedly etc.

Parth


>
> This is my current code:
>   (loop [row []
>          i 0]
>     (if (= i cols)
>       row
>       (recur (assoc row i 0) (inc i))))
>
> It looks pretty bad to me. My java code is more terse than this.
> Thanks for your help.
>   -Cuppo
--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to