Fwd: Array comprehension syntax
brendan at mozilla.com
Sat Sep 22 10:39:27 PDT 2012
Jason Orendorff wrote:
> On Sat, Sep 22, 2012 at 11:21 AM, Brendan Eich<brendan at mozilla.org>
>> Perhaps the thing to do is keep to Python: for+ if? if you get my
> But that isn't Python's syntax.
> Python's comprehensions are: for (for|if)*
Oh! I didn't know you could put if in the middle (or I forgot, more
> Haskell's comprehensions are: (for|if|let)*
> This is what I would prefer for JS.
> Clojure's comprehensions are: for+ (if|while|let)*
> Clojure puts the expression at the right, which I like, for the
> reasons Allen mentioned.
We could do whatever we like but it will be a pain to parse both old and
new in SpiderMonkey!
Actually I think we should not change lightly, not just based on
SpiderMonkey, but on SM + Rhino + (Python being closer to JS in
community intersection size than Clojure).
> CoffeeScript's comprehensions are: for when?
> Only a single 'for' clause. It can't be used to flatten an array of
Yeah, not as strong a precedent -- we should treat JS as big brother
here, over time.
> I actually kind of like Allen's argument about not wanting to
> encourage the use of array comprehensions for complicated use cases.
> However I'm not sure how that squares with a distaste for nanny syntax
Yup. I thought perhaps Allen left out a "not" or otherwise inverted his
More information about the es-discuss