This is a question about how to properly collect the results from a nested for
loop in Clojure. Suppose you want to create a sequence of all vectors [i j]
where 0<=j<i<4
The following code
(for [i (range 1 4)]
(for [j (range i)]
[i j]
)
)
produces
(([1 0]) ([2 0] [2 1]) ([3 0] [3 1] [3 2]))
but what I really want to get is
([1 0] [2 0] [2 1] [3 0] [3 1] [3 2])
What is the right way to do this?
Notice that I'm not interested in this specific sequence. My purpose here is to learn how to collect results from a nested for
loop, which I need for a more complex problem.