Fields of an anonymous function?

Looking at some examples of a package I came across this type of behavior:

function f(n)
    a = n
    x -> x^a
end

g = f(2)

g.a # 2

Can someone point out where that is documented?

If I remember correctly his is an implementation detail of anonymous functions and thus intentially not documented.

1 Like

Strange then that Flux.jl features that behavior in their intro examples: Basics · Flux

I cannot comment on that, but here is some other reference:

1 Like

that’s the part of the documentation I didn’t read :stuck_out_tongue:

That’s the developer docs. Useful if you want to contribute to Julia or understand the internals, but relying on the latter can break your code without warnings.

2 Likes

Hm, I don’t see it in the link; they use that with Affine but that’s a struct, not an anonymous function. Did I just miss it?

In the second code block the following line appears, where linear1 is an anonymous function.

linear1 = linear(5, 3) # we can access linear1.W etc
1 Like

Maybe I should not have used the wording “features that behavior” for an inline comment :thinking: