Is there a way to make reference of the internal variables of an array comprehension? I'm trying to improve this Rosetta Code task:
- https://rosettacode.org/wiki/List_comprehensions#Julia const n = 20 sort(filter(x -> x[1] < x[2] && x[1]^2 + x[2]^2 == x[3]^2, [(a, b, c) for a= 1:n, b=1:n, c=1:n])) In Python it's: In [2]: n = 20 In [3]: [(x,y,z) for x in xrange(1,n+1) for y in xrange(x,n+1) for z in xrange(y,n+1) if x**2 + y**2 == z**2] Out[3]: [(3, 4, 5), (5, 12, 13), (6, 8, 10), (8, 15, 17), (9, 12, 15), (12, 16, 20)] I'll update the task with: julia> [(x, y, z) for x = 1:n, y = 1:n, z = 1:n if x < y && x^2 + y^2 == z^2 ] |> sort 6-element Array{Tuple{Int64,Int64,Int64},1}: (3,4,5) (5,12,13) (6,8,10) (8,15,17) (9,12,15) (12,16,20) But I tried this and it doesn't work, I wonder why? julia> [(x, y, z) for x = 1:n, y = x:n, z = y:n if x^2 + y^2 == z^2] ERROR: UndefVarError: x not defined Is there a way to do this? Thanks in advance!