Re: Reduce context parameter

2013-01-08 Thread Peter van der Zee
On Mon, Jan 7, 2013 at 11:59 PM, Rick Waldron waldron.r...@gmail.com wrote:
 The initialVal argument is _optional_ and undefined is valid — how would you
 decide if what was passed should be initial value or thisArg?

I see. Well, ship has sailed. Thanks.

- peter

...(Could have specced the context parameter to be second, to be
ignored if undefined, and the accumulator third.)
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reduce context parameter

2013-01-08 Thread Brandon Benvie
As I said: 'undefined' and 'not provided' have a complex relationship in
the ES spec. The ship has sailed, but the turd is the shiniest turd you've
ever seen.

On Tuesday, January 8, 2013, Peter van der Zee wrote:

 On Mon, Jan 7, 2013 at 11:59 PM, Rick Waldron 
 waldron.r...@gmail.comjavascript:;
 wrote:
  The initialVal argument is _optional_ and undefined is valid — how would
 you
  decide if what was passed should be initial value or thisArg?

 I see. Well, ship has sailed. Thanks.

 - peter

 ...(Could have specced the context parameter to be second, to be
 ignored if undefined, and the accumulator third.)
 ___
 es-discuss mailing list
 es-discuss@mozilla.org javascript:;
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reduce context parameter

2013-01-07 Thread Andrea Giammarchi
I think to increase confusion with other Array#extras :D

and since we have this specced as it is now, a third parameter for the
context could add even more confusion later on 3

I know, I should not have answered that ...


On Sun, Jan 6, 2013 at 9:48 AM, Peter van der Zee e...@qfox.nl wrote:

 Mostly out of curiosity; why do Array#reduce and reduceRight have no
 context parameter?

 - peter
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reduce context parameter

2013-01-07 Thread Rick Waldron
I know this doesn't answer your question, but Function.prototype.bind makes
thisArg obsolete.

Regarding the origin story, there is some discussion here:
https://mail.mozilla.org/pipermail/es-discuss/2008-June/006431.html

Rick


On Mon, Jan 7, 2013 at 3:56 PM, Andrea Giammarchi 
andrea.giammar...@gmail.com wrote:

 I think to increase confusion with other Array#extras :D

 and since we have this specced as it is now, a third parameter for the
 context could add even more confusion later on 3

 I know, I should not have answered that ...


 On Sun, Jan 6, 2013 at 9:48 AM, Peter van der Zee e...@qfox.nl wrote:

 Mostly out of curiosity; why do Array#reduce and reduceRight have no
 context parameter?

 - peter
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reduce context parameter

2013-01-07 Thread Andrea Giammarchi
Rick you know bind is that slow and it costs on GC if used massively ;-)

I use a lot the second argument in Array#extras and I feel Peter van der
Zee here: reduce/Right should have had that too

br


On Mon, Jan 7, 2013 at 1:10 PM, Rick Waldron waldron.r...@gmail.com wrote:

 I know this doesn't answer your question, but Function.prototype.bind
 makes thisArg obsolete.

 Regarding the origin story, there is some discussion here:
 https://mail.mozilla.org/pipermail/es-discuss/2008-June/006431.html

 Rick


 On Mon, Jan 7, 2013 at 3:56 PM, Andrea Giammarchi 
 andrea.giammar...@gmail.com wrote:

 I think to increase confusion with other Array#extras :D

 and since we have this specced as it is now, a third parameter for the
 context could add even more confusion later on 3

 I know, I should not have answered that ...


 On Sun, Jan 6, 2013 at 9:48 AM, Peter van der Zee e...@qfox.nl wrote:

 Mostly out of curiosity; why do Array#reduce and reduceRight have no
 context parameter?

 - peter
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reduce context parameter

2013-01-07 Thread Rick Waldron
On Monday, January 7, 2013, Andrea Giammarchi wrote:

 Rick you know bind is that slow and it costs on GC if used massively ;-)


This is not my problem, implementors should optimize. bind() would only
occur once per method call.



 I use a lot the second argument in Array#extras and I feel Peter van der
 Zee here: reduce/Right should have had that too


The initialVal argument is _optional_ and undefined is valid — how would
you decide if what was passed should be initial value or thisArg?

Rick






 br






 On Mon, Jan 7, 2013 at 1:10 PM, Rick Waldron 
 waldron.r...@gmail.comjavascript:_e({}, 'cvml', 'waldron.r...@gmail.com');
  wrote:

 I know this doesn't answer your question, but Function.prototype.bind
 makes thisArg obsolete.

 Regarding the origin story, there is some discussion here:
 https://mail.mozilla.org/pipermail/es-discuss/2008-June/006431.html

 Rick


 On Mon, Jan 7, 2013 at 3:56 PM, Andrea Giammarchi 
 andrea.giammar...@gmail.com javascript:_e({}, 'cvml',
 'andrea.giammar...@gmail.com'); wrote:

 I think to increase confusion with other Array#extras :D

 and since we have this specced as it is now, a third parameter for the
 context could add even more confusion later on 3

 I know, I should not have answered that ...


 On Sun, Jan 6, 2013 at 9:48 AM, Peter van der Zee 
 e...@qfox.nljavascript:_e({}, 'cvml', 'e...@qfox.nl');
  wrote:

 Mostly out of curiosity; why do Array#reduce and reduceRight have no
 context parameter?

 - peter
 ___
 es-discuss mailing list
 es-discuss@mozilla.org javascript:_e({}, 'cvml',
 'es-discuss@mozilla.org');
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org javascript:_e({}, 'cvml',
 'es-discuss@mozilla.org');
 https://mail.mozilla.org/listinfo/es-discuss




___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reduce context parameter

2013-01-07 Thread Brendan Eich
The impediment that I recall during ES3.1 days was the accumulator 
parameter to reduce/reduceRight, which wants to come immediately after 
the callback function. Both are mandatory, whereas |thisValue| 
(context, shudder) is optional. So accumulator won.


As for .bind's cost, let's remember Knuth: 
http://en.wikipedia.org/wiki/Program_optimization#When_to_optimize.


/be

Andrea Giammarchi wrote:

Rick you know bind is that slow and it costs on GC if used massively ;-)

I use a lot the second argument in Array#extras and I feel Peter van 
der Zee here: reduce/Right should have had that too


br


On Mon, Jan 7, 2013 at 1:10 PM, Rick Waldron waldron.r...@gmail.com 
mailto:waldron.r...@gmail.com wrote:


I know this doesn't answer your question, but
Function.prototype.bind makes thisArg obsolete.

Regarding the origin story, there is some discussion here:
https://mail.mozilla.org/pipermail/es-discuss/2008-June/006431.html

Rick


On Mon, Jan 7, 2013 at 3:56 PM, Andrea Giammarchi
andrea.giammar...@gmail.com mailto:andrea.giammar...@gmail.com
wrote:

I think to increase confusion with other Array#extras :D

and since we have this specced as it is now, a third parameter
for the context could add even more confusion later on 3

I know, I should not have answered that ...


On Sun, Jan 6, 2013 at 9:48 AM, Peter van der Zee
e...@qfox.nl mailto:e...@qfox.nl wrote:

Mostly out of curiosity; why do Array#reduce and
reduceRight have no
context parameter?

- peter
___
es-discuss mailing list
es-discuss@mozilla.org mailto:es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss



___
es-discuss mailing list
es-discuss@mozilla.org mailto:es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss



___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reduce context parameter

2013-01-07 Thread Andrea Giammarchi
thisArg could have been third optional argument leaving current
implementation as it is but making thisArg possible, IMHO

lucky me I don't use Array#reduce that much neither I need the thisArg so
far so ... OK for me


On Mon, Jan 7, 2013 at 2:59 PM, Rick Waldron waldron.r...@gmail.com wrote:



 On Monday, January 7, 2013, Andrea Giammarchi wrote:

 Rick you know bind is that slow and it costs on GC if used massively ;-)


 This is not my problem, implementors should optimize. bind() would only
 occur once per method call.



 I use a lot the second argument in Array#extras and I feel Peter van der
 Zee here: reduce/Right should have had that too


 The initialVal argument is _optional_ and undefined is valid — how would
 you decide if what was passed should be initial value or thisArg?

 Rick






 br






 On Mon, Jan 7, 2013 at 1:10 PM, Rick Waldron waldron.r...@gmail.comwrote:

 I know this doesn't answer your question, but Function.prototype.bind
 makes thisArg obsolete.

 Regarding the origin story, there is some discussion here:
 https://mail.mozilla.org/pipermail/es-discuss/2008-June/006431.html

 Rick


 On Mon, Jan 7, 2013 at 3:56 PM, Andrea Giammarchi 
 andrea.giammar...@gmail.com wrote:

 I think to increase confusion with other Array#extras :D

 and since we have this specced as it is now, a third parameter for the
 context could add even more confusion later on 3

 I know, I should not have answered that ...


 On Sun, Jan 6, 2013 at 9:48 AM, Peter van der Zee e...@qfox.nl wrote:

 Mostly out of curiosity; why do Array#reduce and reduceRight have no
 context parameter?

 - peter
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reduce context parameter

2013-01-07 Thread Andrea Giammarchi
not always, only when thisArg is needed ... Array#reduce(cb, initialValue[,
thisArg])

if needed, arr.reduce(cb, undefined, obj) does not look that bad, IMHO

again, I m fine with current status ...


On Mon, Jan 7, 2013 at 3:14 PM, Rick Waldron waldron.r...@gmail.com wrote:



 On Monday, January 7, 2013, Andrea Giammarchi wrote:

 thisArg could have been third optional argument leaving current
 implementation as it is but making thisArg possible, IMHO


 lucky me I don't use Array#reduce that much neither I need the thisArg so
 far so ... OK for me


 Sorry, but no—this would force user code to always provide an initialVal,
 even when it would prefer to use the first item the array—which is the
 default when initialVal is omitted.

 Rick




 On Mon, Jan 7, 2013 at 2:59 PM, Rick Waldron waldron.r...@gmail.comwrote:



 On Monday, January 7, 2013, Andrea Giammarchi wrote:

 Rick you know bind is that slow and it costs on GC if used massively ;-)


 This is not my problem, implementors should optimize. bind() would only
 occur once per method call.



 I use a lot the second argument in Array#extras and I feel Peter van
 der Zee here: reduce/Right should have had that too


 The initialVal argument is _optional_ and undefined is valid — how
 would you decide if what was passed should be initial value or thisArg?

 Rick






 br






 On Mon, Jan 7, 2013 at 1:10 PM, Rick Waldron waldron.r...@gmail.comwrote:

 I know this doesn't answer your question, but Function.prototype.bind
 makes thisArg obsolete.

 Regarding the origin story, there is some discussion here:
 https://mail.mozilla.org/pipermail/es-discuss/2008-June/006431.html

 Rick


 On Mon, Jan 7, 2013 at 3:56 PM, Andrea Giammarchi 
 andrea.giammar...@gmail.com wrote:

 I think to increase confusion with other Array#extras :D

 and since we have this specced as it is now, a third parameter for
 the context could add even more confusion later on 3

 I know, I should not have answered that ...


 On Sun, Jan 6, 2013 at 9:48 AM, Peter van der Zee e...@qfox.nlwrote:

 Mostly out of curiosity; why do Array#reduce and reduceRight have no
 context parameter?

 - peter
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss





___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reduce context parameter

2013-01-07 Thread Rick Waldron
On Monday, January 7, 2013, Andrea Giammarchi wrote:

 not always, only when thisArg is needed ... Array#reduce(cb,
 initialValue[, thisArg])

 if needed, arr.reduce(cb, undefined, obj) does not look that bad, IMHO


undefined is a valid initialVal and won't cause reduce to fallback to the
first item in the array (I'd that behaviour was desired). Effectively
changing this:

var array = [2,3,4];

array.reduce(cb.bind(ctx))

To:

array.reduce(cb, array[0], ctx);

Not worth it. In fact, it's not even clear now what that param is even
for...


var

Rick


 again, I m fine with current status ...


 On Mon, Jan 7, 2013 at 3:14 PM, Rick Waldron waldron.r...@gmail.comwrote:



 On Monday, January 7, 2013, Andrea Giammarchi wrote:

 thisArg could have been third optional argument leaving current
 implementation as it is but making thisArg possible, IMHO


 lucky me I don't use Array#reduce that much neither I need the thisArg so
 far so ... OK for me


 Sorry, but no—this would force user code to always provide an initialVal,
 even when it would prefer to use the first item the array—which is the
 default when initialVal is omitted.

 Rick




 On Mon, Jan 7, 2013 at 2:59 PM, Rick Waldron waldron.r...@gmail.comwrote:



 On Monday, January 7, 2013, Andrea Giammarchi wrote:

 Rick you know bind is that slow and it costs on GC if used massively ;-)


 This is not my problem, implementors should optimize. bind() would only
 occur once per method call.



 I use a lot the second argument in Array#extras and I feel Peter van der
 Zee here: reduce/Right should have had that too


 The initialVal argument is _optional_ and undefined is valid — how would
 you decide if what was passed should be initial value or thisArg?

 Rick






 br






 On Mon, Jan 7, 2013 at 1:10 PM, Rick Waldron waldron.r...@gmail.comwrote:

 I know this doesn't answer your question, but Function.prototype.bind
 makes thisArg obsolete.

 Regarding the origin story, there is some discussion here:
 https://mail.mozilla.org/pipermail/es-discuss/2008-June/006431.html

 Rick


 On Mon, Jan 7, 2013 at 3:56 PM, Andrea Giammarchi 
 andrea.giammar...@gmail.com wrote:

 I think to increase confusion with other Array#extras :D

 and since we have this specced as it is now, a third parameter for the
 context could add even more confusion later on 3

 I know, I should not have answered that ...


 On Sun, Jan 6, 2013 at 9:48 AM, Peter van der Zee e...@qfox.nl wrote:

 Mostly out of curiosity; why do Array#reduce and reduceRight have no
 context parameter?

 - peter
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 h https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reduce context parameter

2013-01-07 Thread Andrea Giammarchi
but this is wrong
array.reduce(cb, array[0], ctx);

since index 0 will be looped so first call previous and current will be the
same ... right ? That's why I've used undefined but I understand your
concern so, as it is right now, there's no way to implement the context in
both reduce and reduceRight ... Peter van der Zee use bind :D




On Mon, Jan 7, 2013 at 3:41 PM, Rick Waldron waldron.r...@gmail.com wrote:

 array.reduce(cb, array[0], ctx);
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reduce context parameter

2013-01-07 Thread Brandon Benvie
This is why I ended up using $$ArgumentCount and $$HasArgument('name')
primitive magics. The ES spec's usage of argument exists doesn't really
line up with the semantics of default params. The semantics of default
params are better but it's too late to go back and make explicit
undefined's the same as a lack of a parameter for this stuff (I'm sure
someone out there uses array.reduce(cb, undefined) and depends on it).


On Mon, Jan 7, 2013 at 7:34 PM, Rick Waldron waldron.r...@gmail.com wrote:



 On Monday, January 7, 2013, Andrea Giammarchi wrote:

 but this is wrong
 array.reduce(cb, array[0], ctx);

 since index 0 will be looped so first call previous and current will be
 the same ... right ? That's why I've used undefined but I understand your
 concern so, as it is right now, there's no way to implement the context in
 both reduce and reduceRight ... Peter van der Zee use bind :D


 Yeah, you'd need to mess it up further array.slice(1).reduce... Even less
 worth it now

 Rick







 On Mon, Jan 7, 2013 at 3:41 PM, Rick Waldron waldron.r...@gmail.comwrote:

 array.reduce(cb, array[0], ctx);



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Reduce context parameter

2013-01-06 Thread Peter van der Zee
Mostly out of curiosity; why do Array#reduce and reduceRight have no
context parameter?

- peter
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss