On Wed, Jul 11, 2012 at 7:14 AM, Andreas Rossberg <[email protected]>wrote:
> On 10 July 2012 10:17, Russell Leggett <[email protected]> wrote: > >> Yes, I think that arrays are likely the strongest case for ? on bindings. >> Something like this would be nice: >> let [first,last,?company] = contact.split(","); >> > > Actually, I don't see how this is a case of "? on bindings". In fact, the > '?' would have to be interpreted as part of the array pattern syntax for > the above to make sense (in analogy to object patterns, it happens to be > associated with the implicit property name "2"). > Well, I mean, if you could put it on {}, [], and on variable names, it would have to be part of the expression cover grammer as Brendan was talking about. I suppose technically I should have said "? on expressions that can be interpreted as patterns" or something. In the array case, I guess it would be the equivalent of let {0:first, 1:last, ?2:company} = contact.split(","); Although that highlights an interesting point about object patterns, perhaps it was already covered. If the property is not a valid identifier, it could not use the property shorthand form. This should be an early error. Also related, is there any structural requirement for the value being matched in the case of a [] pattern? If you use ..., there is a requirement to support length. > > AFAICS, '?' on a variable itself would always be redundant, because a > variable pattern is irrefutable anyway. > So you're saying that even this should match in a refutable pattern: let [a,b,c] = [1,2]; I would expect that to fail, especially in a hypothetical pattern matching construct. - Russ > > /Andreas >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

