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

Herby Vojčík herby at mailbox.sk
Wed Jan 2 09:28:01 PST 2013



Brendan Eich wrote:
> Herby Vojčík wrote:
>>> But there is no refutable match future. We need an
>>
>> I don't understand. :-/
>
> We want a way to match with patterns like so:
>
> match (expr) {
> case {must, may?} => ...
> case {always} => ...
> }
>
> In other words, the ? must go in the LHS pattern language, not on the
> RHS of a destructuring binding or assignment expression.

I see. You need o.?p more than o?.p, so you can write (informally) 
o.{foo, ?bar}.

What about the above, then? So you can write foo.?bar to mean `foo.bar 
== null ? Nil : foo.bar`. Then it naturally follows that you can as well 
do `let {must:must, ?may:may} = o` which can be shortened. And it can go 
deeper, since it is Nil.

(but again, syntax may conflict with existing use)

> Ok, but we need a concrete syntax that works if we want anything like
> CoffeeScript's suffix-? operator. And I agree suffix-? is attractive.
> But it seems like a non-starter based on the use of ? in ?: and : in
> labeled statements. Perhaps there's a tweak that saves this concrete
> syntax, though?
>
> /be

Herby


More information about the es-discuss mailing list