Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About the element-wise operation #39269

Closed
tztsai opened this issue Jan 15, 2021 · 3 comments
Closed

About the element-wise operation #39269

tztsai opened this issue Jan 15, 2021 · 3 comments

Comments

@tztsai
Copy link

tztsai commented Jan 15, 2021

In Julia, element-wise operations can be realized by the dot symbol ".". However, for arithmetic operations like "+", "-", "*", "/", etc., the dot is put before the operation symbol, e.g. ".+", ".-", while for functions the dot is put after the function name. Since these operation symbols are also generic functions in Julia (we can write +(1, 2) as an equivalent of 1+2), would it be more consistent if the dot is put after the function for both symbolic operations and named functions? For example, 1+.x instead of 1 .+ x.

@dkarrasch
Copy link
Member

That inconsistency seems to only affect operators for which there is an in-fix notation available. When using pre-fix notation, the same rule applies as for every other function:

julia> x = (1,2)
(1, 2)

julia> (+).(1, x)
(2, 3)

Since in-fix notation is special ("inconsistent") compared to the usual function notation, I'd argue that the inconsistency about the broadcasting dot is consistent. 😄

@fredrikekre
Copy link
Member

xref #8450, #20249 (comment), #20540

@StefanKarpinski
Copy link
Member

The other way to look at this is that in f.(x) the dot is in front of the ( just as it is in front of the + in a .+ b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants