[[strawman:data_parallelism]] |this| and fat arrows

Hudson, Rick rick.hudson at intel.com
Thu Jun 14 13:27:46 PDT 2012

Proposed change to [[strawman:data_parallelism]]

The ParallelArray methods map, combine, reduce, scan, scatter, and filter, each take a kernel function as an argument. Within this kernel function |this| is currently bound to the ParallelArray. This was natural and non-controversial as long as we used the function(){..} form which did not restrict how |this| was bound and explaining the semantics in terms of call or apply was perfectly reasonable. => is likely to change that.  =>, as proposed, enforces a lexical |this| and is semantically different than the function () {..} form. Going forward we expect folks to use the => form more than the function form. For the most part we will be leaving the kernel signatures as they are except that we will no longer bind |this| to the ParalleArray is inside a kernel function. Instead |this| will be bound in accordance to existing JavaScript specifications and [[strawman:data_parallelism]] will no longer refer to |this|. For the combine method which currently gets only an index as an argument we will now also pass the ParallelArray in. If the programmer wants the ParallelArray in methods like reduce or map then it will have to be passed in as a free variable.

We considered and decided not to mimic Array's function (element, index, array) { ... } form. We felt that it causes intellectual confusion about parallel programming since passing in index and array force the programmer to think about things like order and location when using methods like map. It is even more intellectually confusing when using reduce since in a parallel world both of the values passed in may be the results of previous kernel invocations and as such not have an index in any reasonable sense. For combine and filter we pass the ParallelArray in as the second argument. For the other methods one can pass the ParallelArray in using a free variable.

- Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120614/bb126088/attachment.html>

More information about the es-discuss mailing list