Array comprehension syntax
Erik Arvidsson
erik.arvidsson at gmail.com
Mon Sep 24 09:29:53 PDT 2012
That should throw a syntax error since it uses 'in' instead of 'of'.
Other than that I'm in favor of proposal 5 (for (for | if)*).
If we go with the current ES6 draft and you used 'of' instead of 'in'
it would have been a syntax error.
On Mon, Sep 24, 2012 at 11:29 AM, Jason Orendorff
<jason.orendorff at gmail.com> wrote:
> On Sat, Sep 22, 2012 at 11:57 PM, Allen Wirfs-Brock
> <allen at wirfs-brock.com> 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
> favor.)
>
> 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.
>
> -j
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
--
erik
More information about the es-discuss
mailing list