Dot position to broadcast: f. vs .+

I like the new . syntax to broadcast but I have a question about the position of the dot .
Why is the syntax to add elementwise.+ while the syntax to apply a function elementwise is f. ? Is not it inconsistent?

1 Like

There are historical reasons, the generic <f>.(args) syntax is new (v0.5 IIRC), and various .<op> had been added individually as far back as v0.3 IIRC, also, the .<op> ones are all infix.
You can find a lot of discussion about the design decisions of this on GitHub.

f. makes sense for function calls. .* is backwards compatible with previous versions of Julia and MATLAB. I agree that for consistency it would be nice to have *.


We already have *.. It works as function call.

The f.(...) is also consistent in that it’s a broadcast function call, i.e. .().

julia> rand(4) *. rand(4)
ERROR: syntax: invalid identifier name "."

julia> (*).(rand(4),rand(4))
4-element Array{Float64,1}:

That’s not the same thing. I still wonder why the binary version should have the . in front.

1 Like

Because you also don’t write a f. b for normal functions.

And as mentioned above, the operator have . in the front because function call broadcast syntax also have . in the front.

1 Like