Why isn't julia broadcasting through my function

Why isn’t julia broadcasting through the function f2 below:

f1(x) = "scalar"
Base.broadcasted( ::typeof(f1), x ) = "broadcasted"

x = randn(10);

f1.(x)

f2(x) = f1(x)
f2.(x)

I would like f2.(x) to return "broadcasted". It seems to do this at least for operators.

Broadcast just doesn’t work that way. It doesn’t recurse down through the inner layers of your function definitions. The broadcast machinery has no idea that you customized f1 when you passed it a totally different function f2.

julia> f1 === f2
false

Did you mean to isntead make an alias of f1? i.e. something like

julia> f3 === f1
true

julia> f3.(x)
"broadcasted"

OK. Thank you. I thought it did.

Yeah I can see how this might be confusing.

When you write f2(x) = ... that creates a whole new function f2.

Your function just happens to have a very simple implementation which just calls f1, but as far as the broadcast machinery, the type system, and everything are concerned, it’s a totally distinct object.