Array comprehension syntax

Jason Orendorff jason.orendorff at
Mon Sep 24 08:29:29 PDT 2012

On Sat, Sep 22, 2012 at 11:57 PM, Allen Wirfs-Brock
<allen at> wrote:
> actually what I meant to say was that personal preference for ES6 comprehensions, in increasing complexity order is:
>   1) [a non-starter alternative]
>   2) a single for clause followed by a single optional if clause
>   3) one or more for clauses followed by a single optional if clause (what is in the current draft)
>   4) a sequence where each element consists of a for clause and an optional if clause

We disagree on what notion of complexity is important here.

The amount of implementation complexity we're talking about here is
peanuts. I can implement all the options we've discussed by lunchtime.
It's just not an issue.  I can fit all the proposals in a tweet using
a little BNF:

    1. nothing  2. for if?  3. for+ if?  4. (for if?)*
    5. for (for|if)*  6. (for|if|let)*

(I include your proposal 4 for completeness, but no one has really
proposed that.  5 is Python and 6 is Haskell--the two proposals I

But what is actually at issue here is how JS should treat the
developer who writes this:

    books = [book  for author in authors
                     if author.home_state == 'TN'
                       for book in author.books()];

And the options here are (1) run it; (2) throw a SyntaxError.  If it
throws, the developer will be surprised.  They will have to rephrase
their thought to fit our syntactic whims; and they will have to add a
rule to their mental model of the language.  I claim this is the
notion of complexity we should worry about.


More information about the es-discuss mailing list