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

Binary operators and broadcast syntax don't interact well #16993

Closed
fcard opened this issue Jun 17, 2016 · 4 comments
Closed

Binary operators and broadcast syntax don't interact well #16993

fcard opened this issue Jun 17, 2016 · 4 comments
Labels
broadcast Applying a function over a collection parser Language parsing and surface syntax

Comments

@fcard
Copy link
Contributor

fcard commented Jun 17, 2016

Currently, it's necessary to wrap binary operators in parentheses to use them with the new broadcast syntax. Otherwise:

julia> *.(2,[1,2,3])
ERROR: syntax: "*" is not a unary operator
 in eval(::Module, ::Any) at ./boot.jl:231
 in macro expansion at ./REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46

or

julia> +.(1,[1,2,3])
ERROR: syntax: numeric constant "." cannot be implicitly multiplied because it ends with "."
 in eval(::Module, ::Any) at ./boot.jl:231
 in macro expansion at ./REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46

P.S. Also affects the not nearly as important but still happenable cases of using unicode operators as normal variables:

type GreekTemple
  number_of_columns::Int
end
const  = GreekTemple(4)

println(.number_of_collumns) 
# My attempt to build a compilable greek city with unicode art is ruined >:

type Sadness
  sadness_rating::Int
end
const >: = Sadness(10000)

println(>:.sadness_rating) # >: >: >: >: >: >:

edit: I was so used calling custom binary operators unicode that I forgot that some of them are ascii...

@fcard fcard changed the title Unicode operators and broadcast syntax don't interact well Binary operators and broadcast syntax don't interact well Jun 17, 2016
@JeffBezanson JeffBezanson added the parser Language parsing and surface syntax label Jun 17, 2016
@JeffBezanson
Copy link
Member

The case with the "implicitly multiplied" error looks like a bug; there is no numeric constant present so at the very least it needs a better error.

I don't think we ever intended to allow accessing fields of operators with ., but maybe we can. It's a bit ambiguous with e.g. +.2, which is unary + applied to 0.2.

@fcard
Copy link
Contributor Author

fcard commented Jun 17, 2016

Well, a.2 is invalid syntax as well, so +.2 could still mean what it does now. And accessing fields of operators already works with (), as in (⟰).number_of_collumns, so that would just make it easier for when it's necessary... although, I don't see myself personally using that, so I am fine either way, just reportin'!
edit: I think I understand better what you said now, that it would be ambiguous to the user, rather than to the compiler. Fair point! Although, if one is redefining common unary operators and accessing their fields, the entire code must already be looking pretty confusing :P

Also, I just noticed that unary operators other than + and - are giving a different error:

julia> !.(1)
ERROR: syntax: invalid identifier name "."
 in eval(::Module, ::Any) at ./boot.jl:231
 in macro expansion at ./REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46

I am guessing because the parser is trying to parse .(1) separately.
(and - gives numeric constant ".-" instead of just ".")

@stevengj
Copy link
Member

stevengj commented Aug 2, 2016

Note that this should be mostly addressed in 0.6 by #17623, since you will just do 2 .+ [1,2,3] to get a fused broadcast.

@stevengj stevengj added the broadcast Applying a function over a collection label Aug 2, 2016
@stevengj
Copy link
Member

Closed by 17623.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broadcast Applying a function over a collection parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

3 participants