Array comprehension syntax
brendan at mozilla.com
Sat Sep 22 14:52:17 PDT 2012
Allen Wirfs-Brock wrote:
> On Sep 22, 2012, at 10:39 AM, Brendan Eich wrote:
>> Jason Orendorff wrote:
>> 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 meaning, though.
> I don't think so:
>> My personal bias, is that comprehensions are just sugar that are best used to express relatively simple and common construction use cases. Complicated sequences of |for| and |if| clauses will be rarely seen and hence less understandable than the equivalent explicit looping expansions.
Ok, but this doesn't help get your solution to the inherent tension
between "not using comprehensions for complicated cases" vs. "distaste
for nanny syntax restrictions." :-|
> 2) a) one or more [for] clauses followed by a single optional if clause (what is currently in the draft)
How is this not a nanny syntax restriction? The desugaring works without
issue for either of
[x*y for x in range(XDIM) for y in range(YDIM)if x & 1 ]
[x*y for x in range(XDIM) if x & 1 for y in range(YDIM)]
but the last has the virtue of skipping the y iteration for even x values.
More information about the es-discuss