Tuple with unknown n elements

I need to define a tuple of n elements ie (1,2,3,…,n)
where n is the argument of function f as below

function f(n)

None of the following work

x=(1,2,3,…,n)
x=(i, i=1:n)

end

You can use ntuple or a generator comprehension:

julia> ntuple(n -> n, 10)
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

julia> Tuple(i for i in 1:10)
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

3 Likes

Thanks @Mason, really appreciate the help. It works perfectly. I had struggled with this for a while.

2 Likes