Dot position to broadcast: f. vs .+


#1

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?


#2

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.


#3

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 *.


#4

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

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


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

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

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


#6

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.