An array destructing specification choice

David Herman dherman at mozilla.com
Fri Nov 11 17:06:43 PST 2011


On Nov 11, 2011, at 3:36 PM, Allen Wirfs-Brock wrote:

> On Nov 11, 2011, at 3:17 PM, David Herman wrote:
> 
>> A pattern of the form
>> 
>>   [a0, a1, 〰〰, ak, ...r]
>> 
>> desugars to
>> 
>>   a0 = %v[0];
>>   a1 = %v[1];
>>   〰〰
>>   ak = %v[k];
>>   let %length = %v.length;
> 
> do we sample the length here or at the very beginning? It presumably only matter if a %v[n]  is an accessor with side-effects that modify %v.  Generally, the array functions sample length at the beginning before processing any elements.

Beginning seems fine to me.

>> This can be generalized further to allow a fixed number of patterns *after* the ellipsis as well:
>> 
>> A pattern of the form
>> 
>>   [a0, a1, 〰〰, ak, ...r, bn, bn-1, 〰〰, b0]
> 
> We currently haven't specified this syntactic form.  I'm not sure if it adds enough value to justify the added conceptual complexity.

I think it's a pretty big win, and I'd argue it's totally intuitive. The great thing about destructuring is that you can intuit the semantics without actually having to understand the details of the desugaring/semantics.

Also: we'll definitely want to allow it for splicing, so the grammar will have to allow it already, and symmetry/consistency argue for allowing it in destructuring too. Likewise for function formals and actuals.

Dave



More information about the es-discuss mailing list