> On Oct 2, 2016, at 9:30 AM, Olivier Lalonde <[email protected]> wrote:
> 
> So what's the problem with `[...a, last]` that `[...a]` doesn't have? I still 
> don't get it.

Since you don’t know when the iterator produced for `…a` will terminate, 
there’s no way to know when you need to stop iterating `…a` and move onto the 
next item `last`.

A possible workaround would be to track the number of values iterated, and 
compare this index with the `RHS.length/size - 2`, but this would impose a 
maximum of one non-final rest element in the array, and require that the RHS 
necessarily has a known length/size (which would probably end up being a new 
property with a name like Symbol.length or something, added to all collection 
types as an alias for .size() or .length()).

Another option would be to make knowledge of the “maximum” iterated length be 
known at parse-time (something like `[…a{10}, last]`, where `…a`’s iterator 
would stop after at most 10 elements. This wouldn’t require a new `@@length` 
symbol, and would allow multiple non-final rest elements, but it’s not really 
very useful in practice.

> 
> On Sat, Oct 1, 2016 at 7:06 PM, Jordan Harband <[email protected] 
> <mailto:[email protected]>> wrote:
> No, it calls `[Symbol.iterator]()` on the RHS iterable, using the iterator 
> protocol. It has nothing to do with arrays.
> 
> On Sat, Oct 1, 2016 at 12:29 PM, Olivier Lalonde <[email protected] 
> <mailto:[email protected]>> wrote:
> > ```
> > function* ones(){ while(true) yield 1; }
> > var [...a]=ones(); // freezes
> > ```
> 
> So if that freezes, whats the problem with `[...a, last]`? It would just 
> freeze as well...
> 
> > access to array elements may have side effects
> 
> Doesn't `[a, b,...vals]` access array elements?
> 
> 
> On Sat, Oct 1, 2016 at 10:29 AM, Cyril Auburtin <[email protected] 
> <mailto:[email protected]>> wrote:
> ah ok, I forgot about other types of iterables, like infinite ones:
> ```
> function* ones(){ while(true) yield 1; }
> var [...a]=ones(); // freezes
> ```
> 
> 
> 2016-10-01 18:24 GMT+02:00 Dmitry Soshnikov <[email protected] 
> <mailto:[email protected]>>:
> Yeah, because it's not a pattern patching, and access to array elements may 
> have side effects, it's seems hard to specify/implement. Otherwise, 
> destructuring might analyze the pattern, see the last element is required, 
> extract it, and then do iteration for others.
> 
> Dmitry
> 
> 
> On Saturday, October 1, 2016, Michael Theriot <[email protected] 
> <mailto:[email protected]>> wrote:
> I think this is because there's no universal way of determining when an 
> iterator ends. The only way this could work for all iterators would require 
> popping values off of `a` after they've been added.
> 
> On Sat, Oct 1, 2016 at 6:17 AM, Cyril Auburtin <[email protected] <>> 
> wrote:
> It was possibly already discussed, but why isn't:
> ```
> var [...a, last] = [1,2,3];
> ```
> supported?
> 
> I don't see the problem, as long as there's one ... only
> 
> _______________________________________________
> es-discuss mailing list
> [email protected] <>
> https://mail.mozilla.org/listinfo/es-discuss 
> <https://mail.mozilla.org/listinfo/es-discuss>
> 
> 
> 
> 
> _______________________________________________
> es-discuss mailing list
> [email protected] <mailto:[email protected]>
> https://mail.mozilla.org/listinfo/es-discuss 
> <https://mail.mozilla.org/listinfo/es-discuss>
> 
> 
> 
> 
> --
> - Oli
> 
> Oli Lalonde
> http://www.syskall.com <http://www.syskall.com/> <-- connect with me!
> 
> _______________________________________________
> es-discuss mailing list
> [email protected] <mailto:[email protected]>
> https://mail.mozilla.org/listinfo/es-discuss 
> <https://mail.mozilla.org/listinfo/es-discuss>
> 
> 
> 
> 
> 
> --
> - Oli
> 
> Oli Lalonde
> http://www.syskall.com <http://www.syskall.com/> <-- connect with me!
> _______________________________________________
> es-discuss mailing list
> [email protected] <mailto:[email protected]>
> https://mail.mozilla.org/listinfo/es-discuss 
> <https://mail.mozilla.org/listinfo/es-discuss>

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to