Skip to content

(x:y for y in arr) should express an array of objects, no? #1405

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

Closed
dbrans opened this issue May 30, 2011 · 8 comments
Closed

(x:y for y in arr) should express an array of objects, no? #1405

dbrans opened this issue May 30, 2011 · 8 comments

Comments

@dbrans
Copy link

dbrans commented May 30, 2011

Why doesn't

x:y for y in arr

behave like

x y for y in arr

or like

x = y for y in arr

Thanks.

@michaelficarra
Copy link
Collaborator

It looks like {x: (y for y in arr)} to me. As per my normal recommendation, if you're not positive it's absolutely unambiguous, use explicit braces: {x: y} for y in arr.

@TrevorBurnham
Copy link
Collaborator

Michael's right; if you can write x: foo bar, then it's perfectly consistent to be able to write x: y for y in arr. Of course, the spacing (x:y vs. x: y) makes all the difference to human eyes, but we really shouldn't allow compilation precedence to turn on that.

@jashkenas
Copy link
Owner

Explicit braces are great, but I think that dbrans has a point here. If postfix forms close off implicit ), then they should probably also close off implicit } in the same fashion.

@TrevorBurnham
Copy link
Collaborator

Hmm, good point; it would be nice for x:y for y in arr and x y for y in arr to parse similarly.

@michaelficarra
Copy link
Collaborator

Yeah, @jashkenas made a good point there. x: y for y in arr is visually ambiguous, but I guess the technically correct parse should be consistent with the other cases. That is, as long as there isn't a strong use case for the current parse (or, similarly, no use case for the suggested one).

@dbrans
Copy link
Author

dbrans commented Jul 5, 2011

The compiled form of

f x:y if z

also took me by surprise as well. I was expecting it to behave like

f x y if z

Should this be discussed in a separate issue? Thanks.

@TrevorBurnham
Copy link
Collaborator

I think it's an example of the same issue, dbrans. And yes, I'd say it feels like a bug that

f x:y if z

parses as

f {x: y if z}

rather than

f {x:y} if z

@satyr
Copy link
Collaborator

satyr commented Jan 2, 2012

#1871

@satyr satyr closed this as completed Jan 2, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants