Hi,
On 19 Okt., 13:16, Laurent PETIT wrote:
> 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])
And to promote some 1.2 goodness: map-indexed.
user=> (map-indexed #(vector %2 (rem %1 5)) "abcdefghij
2010/10/19 Ulises
> 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
simply don't put a for inside a for:
(for [x (range 5)
y (range 5)]
y)
Hope this helps.
JM
On 19 oct, 06:57, Rising_Phorce wrote:
> Nested For(s) produce lists of lists:
>
> =>(for [x (range 5)]
> (for [y (range 5)]
> y))
>
> ((0 1 2 3 4) (0 1 2 3 4) (0 1 2
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>
U
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, s
On Tue 19/10/10 06:57 , Rising_Phorce josh.fe...@gmail.com sent:
> Nested For(s) produce lists of lists:
>
> =>(for [x (range 5)]
> (for [y (range 5)]
> y))
>
> ((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))
>
> I want to use for(s) in order to use the loop counters from the
> b