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

Pair printing :(get! => 4) doesn't add space to avoid ambiguity #8994

Closed
mauro3 opened this issue Nov 12, 2014 · 6 comments
Closed

Pair printing :(get! => 4) doesn't add space to avoid ambiguity #8994

mauro3 opened this issue Nov 12, 2014 · 6 comments
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@mauro3
Copy link
Contributor

mauro3 commented Nov 12, 2014

The second example should probably work:

julia> Dict(get=>5)
Dict{Function,Int64} with 1 entry:
  get => 5

julia> Dict(get!=>5)
ERROR: syntax: missing comma or ) in argument list
@JeffBezanson
Copy link
Member

Parsing operators is greedy, so it's going to see a !=. You need to add spaces.

@mauro3
Copy link
Contributor Author

mauro3 commented Nov 13, 2014

I see. In that case, maybe add spaces to the string rep:

julia> :(get! => 4)
:(get!=>4)

julia> :(get!=>4)
ERROR: syntax: missing separator in tuple

@ivarne
Copy link
Member

ivarne commented Nov 13, 2014

Yes, that seems reasonable. We should at least improve the heuristics so that the space is printed when it is needed.

@ivarne ivarne changed the title dict syntax Dict(get!=>1) doesn't work Pair printing :(get! => 4) doesn't add space to avoid ambiguity Nov 13, 2014
@ivarne ivarne reopened this Nov 13, 2014
@toivoh
Copy link
Contributor

toivoh commented Nov 13, 2014

Adding a few spaces wouldn't be so bad in general. It seems possible to break all the operators listed in expr_infix in show.jl with greedy operator parsing, not just =>:

julia> :(< : 2)
:(<:2)

julia> :(< :: T)
:(<::T)

julia> :(S{< <: T})
:(S{<<:T})

julia> :((-) -> 1)
:(-->begin  # none, line 1:
            1
        end)

But it would be nice to avoid spaces around :: and ->. Maybe we should print symbols that can cause trouble (such as get! and +) in parentheses?

Another interesting one is

julia> :(+ + +)
:(+(++))

@StefanKarpinski
Copy link
Member

How about just printing the spaces all the time? I find it much more readable and it's way simpler.

@ivarne ivarne added the help wanted Indicates that a maintainer wants help on an issue or pull request label Nov 14, 2014
@ivarne
Copy link
Member

ivarne commented Nov 18, 2014

Hmm.. This probably isn't a backport worthy issue, because the Pair concept is new in 0.4.

waTeim pushed a commit to waTeim/julia that referenced this issue Nov 23, 2014
also enclose operators in parens in some contexts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

5 participants