Giter Club home page Giter Club logo

Comments (16)

jashkenas avatar jashkenas commented on July 23, 2024

It's just the grammar at the moment -- it would definitely be better without. Just simply removing the period raises 36 reduce/reduce errors. If you can figure out a refactor to the grammar that allows it, I'd be glad to take the patch.

from coffeescript.

liamoc avatar liamoc commented on July 23, 2024

Well, python's list comprehensions surround it with []'s, which makes sense as the result is always an array. Perhaps you can just do this?

from coffeescript.

liamoc avatar liamoc commented on July 23, 2024

(This is also done by Haskell, ML and other languages with comprehensions)

from coffeescript.

jashkenas avatar jashkenas commented on July 23, 2024

We could do that, but it would be no better than a period, wouldn't be very CoffeeScript-y, and would muck up the multiline array comprehensions proposed in the other issue. Better for the single liner just to lose the period, if we can fix the grammar.

from coffeescript.

liamoc avatar liamoc commented on July 23, 2024

Hm, examining the grammar, i think the r/r's come from this:

IN PureExpression

The PureExpression seems to be contained, but then if you had an expression like this:

for x in "hi" + for y in "za" if true

You could parse it as either:

for x in ("hi" + for y in "za") if true

or:

for x in ("hi" + (for y in "za" if true))

Any ideas on fixes?

from coffeescript.

liamoc avatar liamoc commented on July 23, 2024

The reason behind this problem is that PureExpression can still be a full Expression provided it includes an operator. If you made PureExpressions not include operators, this problem would be solved.

from coffeescript.

liamoc avatar liamoc commented on July 23, 2024

Alternatively (perhaps better), make operators only take PureExpressions.

The downside of this is that this is necessary:

3 + (if a then b else c)

# not this
3 + if a then b else c

from coffeescript.

zmthy avatar zmthy commented on July 23, 2024

If you resolve this, could we get while as an expression as well?

from coffeescript.

jashkenas avatar jashkenas commented on July 23, 2024

So, tried this, and there's nothing too insurmountable about the grammar, but it does introduce a nasty ambiguity that parses wrong under the current precedence rules. Filters on the comprehensions get parsed as postfix if clauses instead:

highlight(row) for row, i in table if i % 2 is 0

Parses as:

(highlight(row) for row, i in table) if i % 2 is 0

Instead of:

(highlight(row) for row, i in table if i % 2 is 0)

from coffeescript.

liamoc avatar liamoc commented on July 23, 2024

Couldn't this be solved by changing "if" to a different keyword in a comprehension?

from coffeescript.

jashkenas avatar jashkenas commented on July 23, 2024

Yes, yes it could -- perhaps filter.

from coffeescript.

liamoc avatar liamoc commented on July 23, 2024

how about "where"?

for row in table where row isnt null

from coffeescript.

jashkenas avatar jashkenas commented on July 23, 2024

Even better.

from coffeescript.

weepy avatar weepy commented on July 23, 2024

or 'when' to mirror the case statement ?

from coffeescript.

jashkenas avatar jashkenas commented on July 23, 2024

Better yet -- I'll change it.

from coffeescript.

jashkenas avatar jashkenas commented on July 23, 2024

This is now fixed on master, with significant whitespace. Use when to specify the filter over the array comprehension.

from coffeescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.