Re: Function length

2012-06-13 Thread Russell Leggett
On Wed, Jun 13, 2012 at 12:42 PM, Andreas Rossberg wrote: > On 13 June 2012 15:25, Russell Leggett wrote: > > On Wed, Jun 13, 2012 at 5:29 AM, Andreas Rossberg > >> If I understand this correctly, then it will require every function > >> closure to include meta information for performing the ass

Re: Function length

2012-06-13 Thread Andreas Rossberg
On 13 June 2012 15:25, Russell Leggett wrote: > On Wed, Jun 13, 2012 at 5:29 AM, Andreas Rossberg >> If I understand this correctly, then it will require every function >> closure to include meta information for performing the associated >> pattern match. Or, when you actually want this to be opt

Re: Function length

2012-06-13 Thread Russell Leggett
On Wed, Jun 13, 2012 at 5:29 AM, Andreas Rossberg wrote: > On 12 June 2012 23:57, Russell Leggett wrote: > > This thread gave me an interesting idea on how to possibly attack pattern > > matching in ES6 with no new syntax, and still leave room for more sugar > > later. It actually comes from thin

Re: Function length

2012-06-13 Thread Andreas Rossberg
On 12 June 2012 23:57, Russell Leggett wrote: > This thread gave me an interesting idea on how to possibly attack pattern > matching in ES6 with no new syntax, and still leave room for more sugar > later. It actually comes from thinking about the original issue with > function.length and using it

Re: Function length

2012-06-13 Thread Tom Ellis
I like the look of this: > function add(a,b){ > return a + b; > } > > add.matches(1,2); // => true > add.matches(1); // => false > add.matches(1,2,3); => false I've never had the need to use function.length, I probably will at some point though. If you did somethi

Re: Function length

2012-06-12 Thread Russell Leggett
On Tue, Jun 12, 2012 at 1:06 PM, Brendan Eich wrote: > Russell Leggett wrote: > >> It does bring up something else, though, that I've avoided mentioning so >> far, which is pattern matching. I haven't mentioned it because there is >> clearly a strawman > doku.php?i

Re: Function length

2012-06-12 Thread Brendan Eich
Russell Leggett wrote: It does bring up something else, though, that I've avoided mentioning so far, which is pattern matching. I haven't mentioned it because there is clearly a strawman for it, and that never made it to harmon

Re: Function length

2012-06-12 Thread Russell Leggett
On Mon, Jun 11, 2012 at 3:50 PM, Brendan Eich wrote: > Irakli Gozalishvili wrote: > >> Sorry for not being clear about this. Here is a simplified example of the >> implementation: >> https://gist.github.com/**2911817 >> >> Also this is just a single particular ex

Re: Function length

2012-06-12 Thread Felix Böhm
The big question is whether Function#length should represent minimum or the maximum amount of arguments. That means that a rest parameter could have zero elements, and optional parameters could fall back to their default value. The minimum approach wouldn't count them, the maximum would expec

Re: Function length

2012-06-11 Thread Brendan Eich
Irakli Gozalishvili wrote: Sorry for not being clear about this. Here is a simplified example of the implementation: https://gist.github.com/2911817 Also this is just a single particular example, but I expect there to be more. I think what I'm really asking for is a way to know if …rest is be

Re: Function length

2012-06-11 Thread Mariusz Nowak
I find Function 'length' as very useful property (I use it in some low-level functional stuff). I also think that defining functions so it reflects only required arguments is very sane decision. In that light I would also expect ...rest to not be counted in Function length. +1 for

Re: Function length

2012-06-11 Thread Irakli Gozalishvili
Sorry for not being clear about this. Here is a simplified example of the implementation: https://gist.github.com/2911817 Also this is just a single particular example, but I expect there to be more. I think what I'm really asking for is a way to know if …rest is being used. Also IMO arrow fu

Re: Function length

2012-06-11 Thread Brendan Eich
I would not mind removing Function 'length' but on the web you cannot deprecate and any browser daring to remove will appear broken to users not involved in the content or the engine, and users switch browsers. Anyway, back to reality: foo.length is in ECMA-262 and we need to sp

Re: Function length

2012-06-11 Thread Allen Wirfs-Brock
On Jun 11, 2012, at 10:56 AM, Irakli Gozalishvili wrote: >> I don't think any library should ever rely on f.length. > > That's a wrong attitude, there always will be legitimate uses of any > feature, otherwise such features are just harmful & IMO should be deprecated > / removed. Let me t

Re: Function length

2012-06-11 Thread Irakli Gozalishvili
> I don't think any library should ever rely on f.length. > > That's a wrong attitude, there always will be legitimate uses of any feature, otherwise such features are just harmful & IMO should be deprecated / removed. > It is not a > reliable source of information (f might use 'arg

Re: Function length

2012-06-11 Thread Andreas Rossberg
On 10 June 2012 03:52, Irakli Gozalishvili wrote: > I just noticed strange behavior in spider monkey implementation of rest > arguments: > > (function(a, b, ...rest) {}).length // => 2 > > I think ignoring `rest` in length is pretty counter intuitive. For example I > have small utility function th

Re: Function length

2012-06-10 Thread John Tamplin
On Sun, Jun 10, 2012 at 12:48 PM, Irakli Gozalishvili wrote: > Never the less problem still stands, but maybe there are other ways to > solve it. Only solution I'm left with so far is utility function like this: > > function hasRest(f) { > return !!~String(f).split('\n').shift().indexOf('...')

Re: Function length

2012-06-10 Thread Irakli Gozalishvili
Never the less problem still stands, but maybe there are other ways to solve it. Only solution I'm left with so far is utility function like this: function hasRest(f) { return !!~String(f).split('\n').shift().indexOf('...') } Which is bad, specially toString of function is not guaranteed to

Re: Function length

2012-06-09 Thread Allen Wirfs-Brock
On Jun 9, 2012, at 6:52 PM, Irakli Gozalishvili wrote: > I just noticed strange behavior in spider monkey implementation of rest > arguments: > > (function(a, b, ...rest) {}).length // => 2 > That answer is consistent with what is specified in the ES6 draft spec. The actual value is specifi

Re: Function length

2012-06-09 Thread Erik Arvidsson
; named parameters. The length in ES5 is not very consistent. For ES6 we decide that we wanted the function length to be used to tell how many required parameters a function has. Today rest params are done using arguments: (function(a, b) { var rest = Array.prototype.slice.call(arguments, 2); }).l

Re: Function length

2012-06-09 Thread Rick Waldron
On Saturday, June 9, 2012 at 11:53 PM, Erik Arvidsson wrote: > Don't you want to use arguments.length instead of function.length? > On Jun 9, 2012 6:53 PM, "Irakli Gozalishvili" (mailto:rfo...@gmail.com)> wrote: > > I just noticed strange behavior in spider monkey implementation of rest > > a

Re: Function length

2012-06-09 Thread Erik Arvidsson
Don't you want to use arguments.length instead of function.length? On Jun 9, 2012 6:53 PM, "Irakli Gozalishvili" wrote: > I just noticed strange behavior in spider monkey implementation of rest > arguments: > > (function(a, b, ...rest) {}).length // => 2 > > I think ignoring `rest` in length is p

Function length

2012-06-09 Thread Irakli Gozalishvili
I just noticed strange behavior in spider monkey implementation of rest arguments: (function(a, b, ...rest) {}).length // => 2 I think ignoring `rest` in length is pretty counter intuitive. For example I have small utility function that I use to dispatch depending on argument length. var sum