Comprehensions, Where Art Thou?

Brendan Eich brendan at mozilla.org
Mon Aug 11 11:13:35 PDT 2014


Tab Atkins Jr. wrote:
> No, that's standard.  It's not Pythonic to have comprehensions that
> large, as it obscures rather than enlightens, particularly some of
> those crazier nested ones that Dave is using.

Dave was translating mostly-mechanically from prior source.

>    If your comprehension
> doesn't fit in 80chars, you're probably doing something wrong, and
> should break it down to a real for loop.

See the original in Python from Peter Norvig, and an 
ES6-with-comprehensions version based on my JS1.8 "port" of Peter's 
original:

http://norvig.com/sudoku.html

http://mxr.mozilla.org/mozilla-central/source/js/src/tests/ecma_6/Comprehensions/sudoku.js?raw=1

Did you find Peter's comprehensions overlong? I did not, but that's not 
to say anything about the original is "easy". It's a great read, 
especially in the posted "literate code" form.

Beyond the conciseness, comprehensions should afford engines the ability 
to optimize and parallelize. One of the breakthroughs in removing 
comprehensions from ES6 was everyone wanting to generalize from 1 
(Array) to N>>1 (iterables, lazy and eager; ParallelArray; other 
array-likes).

Rather than adding mappar or pmap, one can use receiver-dispatched 
methods polymorphically as in JS funky-OOP today, no need for new 
delimiters after [] and () around for/of/if comprehension syntax. We 
really are out of delimiters!

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140811/a4b75cef/attachment-0001.html>


More information about the es-discuss mailing list