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

spaces in comprehensions #27400

Closed
atbug opened this issue Jun 3, 2018 · 4 comments
Closed

spaces in comprehensions #27400

atbug opened this issue Jun 3, 2018 · 4 comments
Labels
parser Language parsing and surface syntax

Comments

@atbug
Copy link

atbug commented Jun 3, 2018

On both 0.7.0-alpha and 0.6.3:

julia> [1 +1 for i in 1:2]
ERROR: syntax: invalid comprehension syntax

julia> [1+1 for i in 1:2]
2-element Array{Int64,1}:
 2
 2

julia> [1+ 1 for i in 1:2]
2-element Array{Int64,1}:
 2
 2

julia> [1 + 1 for i in 1:2]
2-element Array{Int64,1}:
 2
 2

I think the intention of [1 +1 for i in 1:2] is clearly 1+1, not [1, +1], unless there are some other confusing situations?

@atbug atbug changed the title mysterious behavior of space in nested comprehensions spaces in comprehensions Jun 3, 2018
@tomaklutfu
Copy link
Contributor

Though intention is that so, I think it is ambiguous with infix + methods.

@garrison
Copy link
Member

garrison commented Jun 3, 2018

Another one I've noticed:

julia> [1 +
        x for x in 1:4]
ERROR: syntax: invalid comprehension syntax

See also #9494

@ararslan ararslan added the parser Language parsing and surface syntax label Jun 3, 2018
@JeffBezanson
Copy link
Member

The issue here is hcat syntax, where [1 -2] makes a 1x2 array. So it thinks [1 +1 ...is an hcat, at which point it's too late for it to be a comprehension. The case with the newline,

[1 +
 x for ...

seems like it could maybe be made to work.

As a footnote, since it's come up in the past, note that

[1
 + x for ...

is never going to work. Since we don't require ; statement separators, we can't join expressions with operators on the next line.

@JeffBezanson
Copy link
Member

The case with the line break was fixed by #20265. The other case I don't think can be fixed.

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

No branches or pull requests

5 participants