Comments on Refutable Patterns proposal

Andreas Rossberg rossberg at
Thu Mar 21 05:32:06 PDT 2013

On 21 March 2013 00:04, Axel Rauschmayer <axel at> wrote:
> - Would love to see examples for arrays. Especially if there are more
> element patterns (lhs) than array elements (rhs).

Good point. I added some.

> - Possible future extensions: Make pattern after "..." optional, allow "..."
> in the middle of an array. Examples:
>     let [...front, last] = someArray;
>     let [..., last] = someArray;
>     let [first, ...] = someArray;

Yeah, rest patterns in other places were already decided out of scope
for ES6 a while ago. And I did not include them here either because it
is far from clear what a reasonable semantics should be for all kinds
of corner cases. Just consider:

  let [a, b, c, ...middle, x, y, z] = {'0': 0, '4': 4, length: 3}

And with rest patterns at the end only, I don't think you'd ever want
to write "..." without a subpattern. The only difference between [x,
y] and [x, y, ...] would be that the latter (somewhat redundantly)
checks the presence of a length property.

> - Missing parameter in third-last line?
> Match(ElementPatterns, value, index, soft) =
>    assert IsObject(value)
>    case ElementPatterns of
>       ElementPattern =>
>          Match(ElementPattern, value, index, soft)
>       ElementPattern "," ElementPatterns =>
>          if Match(ElementPattern, value, index, soft) = SUCCESS then
>             Match(ElementPatterns, value, soft)   (* Missing? index+1 *)
>          else
>             FAILURE

Oops, you're right. Fixed that and two other things regarding array patterns.

Thanks for the comments.


More information about the es-discuss mailing list