Julia - n-nested loops

I'm trying to make n-nested loops method in Julia

function fun(n::Int64)
    @nloops n i d->1:3 begin\n
        @nexprs n j->(print(i_j))\n
    end
end

But the definition of @nloops is limited

_nloops(::Int64, ::Symbol, ::Expr, ::Expr...)

and I get an error

_nloops(::Symbol, ::Symbol, ::Expr, ::Expr)

Is there any way to make this work? Any help is much appreciated

EDIT:

As a result, I used the combination method

For my problem, I needed to get all k-combinations of indices to pull values ​​from an array, so the loops should have looked like

for i_1 in 1:100
    for i_2 in i_1:100
        ...
           for i_k in i_[k-1]:100
+4
source share
2 answers

- , : , , . Julia , n , . , n, .

+6

julia-0.4 :

function fun(n::Int)
    for I in CartesianRange(ntuple(d->1:3, n))
        @show I
    end
end

Base.Cartesian( ). , , , " ", n ; , " ". . http://julialang.org/blog/2016/02/iteration , .

+3

All Articles