Refutable destructuring

Rick Waldron waldron.rick at gmail.com
Fri Aug 9 16:17:55 PDT 2013


On Fri, Aug 9, 2013 at 6:40 PM, Brendan Eich <brendan at mozilla.com> wrote:

> On Aug 9, 2013, at 3:32 PM, Rick Waldron <waldron.rick at gmail.com> wrote:
>
> On Fri, Aug 9, 2013 at 5:54 PM, Axel Rauschmayer <axel at rauschma.de> wrote:
>
>> AFAICT, there is no current consensus on whether destructuring assignment
>> is refutable by default or not:
>>
>> https://github.com/rwldrn/tc39-notes/blob/master/es6/2013-07/july-23.md#44-consider-deferring-es6-refutable-matching
>>
>> Could we make destructuring assignment fail soft and introduce a marker
>> for refutable parts of a pattern (e.g. a prefix `!`):
>>
>>     let { !a: foo, b: bar } = { a: 1 };  // ok: foo = 1, b = undefined
>>     let { !a: foo, b: bar } = { };  // exception
>>
>> This would have one advantage: It would be possible to bring this
>> operator to parameter declarations (allowing one to declaratively specify a
>> minimum arity). Then destructuring assignment and parameter handling would
>> work very similarly.
>>
>>     function bla(!mandatoryArg, optionalArg1, optionalArg2 = 123) {
>>         ...
>>     }
>>
>>
>
> While I agree this is interesting and should be explored further, I reject
> the proposal to add more meaning to the "!" character. Given this proposal,
> "!" would sometimes mean "not" or "negate" (as in it's current form) and
> sometimes mean "a required thing". Meanwhile, "refute" is a synonym for
> "negate", which is the opposite of what you're claiming the semantics would
> be, ie. irrefutable, "impossible to omit"
>
>
> No.
>
>
> or "impossible to deny [a value for this identifier binding]".
>
>
>
> No, refutable is what Axel means. He wants matching, so a failure or
> refutation to cause fall through to next match. What we have in JS now with
> o.p and in ES6 with let {p} = o; is irrefutable -- no way to mismatch, if
> the property is missing you get undefined.
>
> So ! Is not too far off the mark. Recall that the late proposal was to
> unify patterns used now in destructuring and later in matching by requiring
> ? for irrefutability and making lack of ? mean "refutable".
>


My argument was specifically about the current meaning of the ascii
exclamation "!" and that assigning it an additional context-based meaning
that's quite the opposite of the current unary operator meaning, isn't a
proposal that I would support. This is stated with no regard for previous
refutable matching proposals.

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


More information about the es-discuss mailing list