fail-fast object destructuring (don't add more slop to sloppy mode)

Brendan Eich brendan at
Wed Jan 2 10:13:46 PST 2013

Herby Vojčík wrote:
> Brendan Eich wrote:
>> Herby Vojčík wrote:
>>> Then it naturally follows that you can as well do `let {must:must,
>>> ?may:may} = o` which can be shortened.
>> Yes, that was the syntax we talked about earlier this year, but I think
>> CoffeeScript and TypeScript make a case for suffix-?.
>>> And it can go deeper, since it is Nil.
>> What is Nil? There is no requirement with ? in the pattern language (on
>> the LHS) for the RHS to be of any particular type.
>> I like Nil, and it may help rescue ?. the existential operator strawman.
>> But that is in the expression language, not in the pattern language.
> I like not to make things unnecessarily disjoint. Here I see the 
> possibility of having pattern language (in future patterns as well as 
> in present destructuring) having same semantics as the expression 
> language _with_throwing_on_nonexistent_property_ (that is what you 
> asked in this thread, unless I did not understand).

I'm with you on wanting equivalences, such that "same semantics" works 
up to some limit (proxies, perhaps -- I'm not sure). Since 
pattern-matching is in the future it is possible it could diverge 
observably from equivalent expression language, for good reason.

If there's no reason in the future to diverge, great.

We need to detail how Nil works, how it cannot be wrapped or observed, 
etc. in order to maintain equivalence.

> That is, these are identical, except the syntax:
>     r = o.p.q    {p: {q: r}} = o
>     r = o.?p.q    {?p: {q: r}} = o
>     P=o.p; Q=o.?q    {p: P, ?q: Q} = o

Here I part company only on syntax:

     r = o?.p.q       {p?: {q: r}} = o
     P=o.p; Q=o?.q    {p: P, q?: Q} = o

And of course, the short-hand works:

     p=o.p; q=o?.q    {p, q?} = o

> With "it can go deeper, since it is Nil" I meant the second line, 
> where (o.?p) produces Nil, so o.?p.q being Nil.q produces Nil as well, 
> without throw.

Yes, I agree (already :-P) that this is a good idea for saving the 
existential operator.


More information about the es-discuss mailing list