Enforcing arity?

Axel Rauschmayer axel at rauschma.de
Mon Jan 7 12:12:46 PST 2013


I’m torn: On one hand, I love the cleverness of it and it is certainly a good solution (and one that doesn’t necessitate introducing new language features).

On the other hand, I’m wondering if it wouldn’t be cleaner to have a per-function flag that tells JavaScript to enforce the specified arity (which can be done quite precisely, thanks to ES6’s advanced parameter handling). One possibility for setting such a flag are Python-style decorators:
http://www.python.org/dev/peps/pep-0318/

Axel

On Jan 7, 2013, at 20:33 , Brendan Eich <brendan at mozilla.com> wrote:

> Jason Orendorff wrote:
>> On Sun, Jan 6, 2013 at 6:31 PM, Axel Rauschmayer <axel at rauschma.de <mailto:axel at rauschma.de>> wrote:
>> 
>>    What is the simplest way of enforcing an arity in ES6? Doesn’t it
>>    involve arguments?
>> 
>> 
>> Hmm. Can you do this?
>> 
>>    function f(x, y, ...[]) {}
> 
> The question is, with refutable-by-default, does the empty array pattern fail on any non-empty arraylike match target? If yes, then we need a way to match prefixes of arraylikes (including empty prefixes!):
> 
>  let [] = must_be_empty();
>  let [...many] = however_many();
>  let [first?, second?] = two();
> 
> I buy it!
> 
> /be
> 

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130107/6305473b/attachment.html>


More information about the es-discuss mailing list