Accessing Internal variables in a function

I think it’s something specific to closure. As the documentation says:

A closure is simply a callable object with field names corresponding to captured variables. For example, the following code:

function adder(x)
    return y->x+y
end

is lowered to (roughly):

struct ##1{T}
   x::T
end

(_::##1)(y) = _.x + y

function adder(x)
    return ##1(x)
end

So because the W is captured by the closure, you can access it like a field.

3 Likes