2010/10/19 Ulises <ulises.cerv...@gmail.com>

> Alternatively you can do:
>
> user> (def x 5)
> user> (def y 7)
> user> (take (* x y) (cycle (range x)))
> (0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4)
> user>
>

And don't forget that seqs produced by range, cycle, etc., are lazy
(elements produced "on demand" - modulo chunked seqs optimizations-), so
(cycle (range 5)) may be sufficient in your case, e.g. if you use it to
"index" a fixed size collection (used in conjunction with 'map, the fixed
size collection's size will limit things :

user=> (def x 5)
#'user/x
user=> (def c ["a" "b" "c" "d" "e" "f"])
#'user/c
user=> (map vector c (cycle (range x)))
(["a" 0] ["b" 1] ["c" 2] ["d" 3] ["e" 4] ["f" 0])
user=>

HTH,

-- 
Laurent

-- 
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

Reply via email to