A better future for comprehensions -...
Transcript of A better future for comprehensions -...
![Page 1: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/1.jpg)
A better future for comprehensions
Dave Herman
![Page 2: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/2.jpg)
[for (x of y) if (p(x)) f(x)]
(for (x of y) if (p(x)) f(x))
![Page 3: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/3.jpg)
• Parallel JS is moving in the direction of parallel pipelines – a natural fit for comprehensions.
• Three strikes and you refactor!
• LINQ: one comprehension syntax, unbounded number of (user-definable) traversable datatypes.
![Page 4: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/4.jpg)
let a = for (x of a1)
for (y of a2)
if (y > x)
{ x, y };
![Page 5: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/5.jpg)
let i = for (x of map1.keys())
for (y of map2.keys())
if (y > x)
{ x, y };
![Page 6: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/6.jpg)
let p = for (x of a1.parallel())
for (y of a2.parallel())
if (y > x)
{ x, y };
![Page 7: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/7.jpg)
• The LINQ idea (which is actually the Haskell idea): comprehensions desugar into generic combinators.
• Any datatype that supports those combinators automatically gets to play along.
![Page 8: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/8.jpg)
• Defer comprehensions from ES6.
• Jafar and I will present an ES7 proposal for generalized comprehensions.
![Page 9: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/9.jpg)
Generator
Iterator.prototype
.prototype
[[Prototype]]
generator
[[Prototype]]
[[Prototype]] ??
![Page 10: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/10.jpg)
Iterator.prototype.
zip
filter
map
...
![Page 11: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/11.jpg)
table.keys().map(...)
.filter(...)
!
// versus
!
import { map, filter } from "itertools";
filter(map(table.keys(), ...), ...);
![Page 12: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/12.jpg)
(new Iterator({
next() { ... }
})).map(...)
![Page 13: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/13.jpg)
5 Jun 14 Resolutions
![Page 14: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel](https://reader036.fdocuments.in/reader036/viewer/2022071412/6108dfa3391a02694b4cfe4f/html5/thumbnails/14.jpg)
• Agree to defer comprehensions.
• No future-proofing placeholder objects (can be added later with low compatibility risk).
• May not generalize generator comprehensions since first RHS eagerly evaluated; more work to do.