My first guess would be to go to Base.Cartesian looking for the right macro, these macros are used to construct an arbitrary number of nested loops at compile time. But here maybe you simply need somethign recursive alike the following:
function make(k,n)
if k == 0
return 1:n
else
return permutations(make(k-1,n))
end
end
?
EDIT: by the way,
does not correspond to what your code does for k=2, which iterates over permutation(1:n) x permutations(1:n) ? Perhaps you could clarify a bit what you need ?
EDIT: I think I understood what you want, which could be this:
using Base.Iterators
k=2
n=2
for indices in product((permutations(1:n) for i in 1:k)...)
@show indices
end
which outputs
indices = ([1, 2], [1, 2])
indices = ([2, 1], [1, 2])
indices = ([1, 2], [2, 1])
indices = ([2, 1], [2, 1])
Thanks, this does the job. Just, as i need the (k!)^n permutations, the k and n indices must be interchanged, as for the solution given by @irvn (my bad, my question was not correct). This is what i’ve got: