Comments on Refutable Patterns proposal

Brendan Eich brendan at mozilla.com
Thu Mar 21 23:15:59 PDT 2013


Brandon Benvie wrote:
> On 3/21/2013 10:54 AM, Tab Atkins Jr. wrote:
>> On Thu, Mar 21, 2013 at 10:51 AM, Brandon Benvie 
>> <bbenvie at mozilla.com> wrote:
>>> On 3/21/2013 10:14 AM, Axel Rauschmayer wrote:
>>>>> 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.
>>>> Ah! I would expect [x,y] to only match arrays whose length is 2. Is 
>>>> there a
>>>> benefit to being more lenient?
>>> I wouldn't expect that at all, for the same reason I would expect 
>>> `let { x,
>>> y } = { x: 1, y: 2, z: 3 }` to work.
>> And in Python, for example, I often get annoyed when the interpreter
>> reminds me that the length of an unpacked tuple must be the same as
>> the originating tuple, even if I'm intentionally ignoring the end of
>> it.
>>
>> ~TJ
> This also. I think a common use case is to grab the items at the 
> beginning of a variable (or even unknown) length array. I also don't 
> see the benefit of requiring exact length matching, especially when it 
> would require adding additional syntax to bring back the ability to 
> work with variable/unknown length arrays.

We have talked of literals in the pattern language:

   let {0:x, 1:y, length:2} = pair_only_please();

It's a pain to write an object pattern instead of an array, but this is 
the exception to the rule, or would be were it supported. And it may be 
in the future.

/be


More information about the es-discuss mailing list