This is how you could put that into a generated function and use it
@generated function many(input, ranges::NTuple{N,T} ) where {N,T}
quote
@nextract $N r ranges
@nextract $N f input
$(Expr(:(=), Symbol(:fval_,N+1) , 3))
@nloops $N i n->1:r_n d -> fval_d = f_d(fval_{d+1}, i_d) begin
@nexprs $N k->(println(fval_k))
end
end
end
in = (+,-,atan,/) # Some two-argument functions
many(in, (3,3,3,3))
Note that this does not actually calculate anything interesting at the moment, just a demo.