Re: @@iterator in arguments object
You're right, defaults would take care of those few places reducing the need to reference the arguments object entirely. I think there may be one or two exceptions, like when there's no default value but an explicit `undefined` is coerced to undefined but a lack of the argument becomes an empty string. I guessable default value of the empty string may cover this but I have a nagging feeling there's some exception in one of the builtin methods that defies all attempts that don't rely on arguments.length, but I can't figure out what that method might be. On Saturday, December 22, 2012, Axel Rauschmayer wrote: Parameter default values weren't good enough for this? ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
Brandon Benvie wrote: You're right, defaults would take care of those few places reducing the need to reference the arguments object entirely. I think there may be one or two exceptions, like when there's no default value but an explicit `undefined` is coerced to undefined but a lack of the argument becomes an empty string. I guessable default value of the empty string may cover this but I have a nagging feeling there's some exception in one of the builtin methods that defies all attempts that don't rely on arguments.length, but I can't figure out what that method might be. If it exists, it's just bad precedent. You could always use an explicit rest parameter as the only formal parameter and still dispense with arguments in new code. So let's say s/could/should/. /be ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
Yeah good point, and you don't even need to dump all the named params. In light of this, I think its feasible to pronounce the arguments object in ES6 as vestigial and ready for retirement (except for all the legacy code of course). ES6 claims another victim: [object Arguments]. On Sunday, December 23, 2012, Brendan Eich wrote: You could always use an explicit rest parameter as the only formal parameter and still dispense with arguments in new code. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
On Dec 23, 2012, at 9:38 AM, Brendan Eich wrote: Brandon Benvie wrote: You're right, defaults would take care of those few places reducing the need to reference the arguments object entirely. I think there may be one or two exceptions, like when there's no default value but an explicit `undefined` is coerced to undefined but a lack of the argument becomes an empty string. I guessable default value of the empty string may cover this but I have a nagging feeling there's some exception in one of the builtin methods that defies all attempts that don't rely on arguments.length, but I can't figure out what that method might be. If it exists, it's just bad precedent. You could always use an explicit rest parameter as the only formal parameter and still dispense with arguments in new code. So let's say s/could/should/. And you can then use destructuring assignment to parse out that rest parameter into one or more signature patterns. Allen ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
Arguments object is used here to fill the rest void, but also as an argument to apply (after converting into a real array) when writing wrapper functions; eg monkey patches, userspace profiling, etc. Is there an ES6 way to use apply on rest params? If not, arguments must live on. Sent from my iPhone On 2012-12-23, at 12:48, Brandon Benvie bran...@brandonbenvie.com wrote: Yeah good point, and you don't even need to dump all the named params. In light of this, I think its feasible to pronounce the arguments object in ES6 as vestigial and ready for retirement (except for all the legacy code of course). ES6 claims another victim: [object Arguments]. On Sunday, December 23, 2012, Brendan Eich wrote: You could always use an explicit rest parameter as the only formal parameter and still dispense with arguments in new code. ___ 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: @@iterator in arguments object
Something like this? var partial = (fn, ...args) = function(...newArgs){ return fn.apply(this, args.concat(newArgs)); }; On Sun, Dec 23, 2012 at 2:26 PM, Wes Garland w...@page.ca wrote: Arguments object is used here to fill the rest void, but also as an argument to apply (after converting into a real array) when writing wrapper functions; eg monkey patches, userspace profiling, etc. Is there an ES6 way to use apply on rest params? If not, arguments must live on. Sent from my iPhone On 2012-12-23, at 12:48, Brandon Benvie bran...@brandonbenvie.com wrote: Yeah good point, and you don't even need to dump all the named params. In light of this, I think its feasible to pronounce the arguments object in ES6 as vestigial and ready for retirement (except for all the legacy code of course). ES6 claims another victim: [object Arguments]. On Sunday, December 23, 2012, Brendan Eich wrote: You could always use an explicit rest parameter as the only formal parameter and still dispense with arguments in new code. ___ 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: @@iterator in arguments object
Wes Garland wrote: Arguments object is used here to fill the rest void, but also as an argument to apply (after converting into a real array) when writing wrapper functions; eg monkey patches, userspace profiling, etc. Is there an ES6 way to use apply on rest params? A rest parameter is a real Array instance. Function.prototype.apply works on array instances. What's the problem? /be If not, arguments must live on. Sent from my iPhone On 2012-12-23, at 12:48, Brandon Benvie bran...@brandonbenvie.com mailto:bran...@brandonbenvie.com wrote: Yeah good point, and you don't even need to dump all the named params. In light of this, I think its feasible to pronounce the arguments object in ES6 as vestigial and ready for retirement (except for all the legacy code of course). ES6 claims another victim: [object Arguments]. On Sunday, December 23, 2012, Brendan Eich wrote: You could always use an explicit rest parameter as the only formal parameter and still dispense with arguments in new code. ___ 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
Re: Flexible String Representation - full Unicode for ES6?
On Saturday, December 22, 2012 at 12:34 AM, Chris Angelico wrote: On Sat, Dec 22, 2012 at 4:09 PM, Erik Arvidsson erik.arvids...@gmail.com wrote: On Fri, Dec 21, 2012 at 6:45 PM, Chris Angelico ros...@gmail.com wrote: There is an alternative. Python (as of version 3.3) has implemented a new Flexible String Representation, aka PEP-393; the same has existed in Pike for some time. A string is stored in memory with a fixed number of bytes per character, based on the highest codepoint in that string - if there are any non-BMP characters, 4 bytes; if any U+0100-U+, 2 bytes; otherwise 1 byte. This depends on strings being immutable (otherwise there'd be an annoying string-copy operation when a too-large character gets put in), which is true of ECMAScript. Effectively, all strings are stored in UCS-4/UTF-32, but with the leading 0 bytes elided when they're not needed. This is how most VMs already work. I agree with you that it would be a better world if this was the case but I don't hear you suggesting how we might be able to change this without breaking the web? Why, if that's how it's already being done, can't there be an easy way to expose it to the script that way? Just flip the Big Red Switch and suddenly be fully Unicode-safe? Yes, it's backward-incompatible, but if the script can have some kind of marker (like use strict) to show that it's compliant, That would effectively be a second version of the language, which violates the 1JS promise (no opt-ins or unlockables) Rick or if the engine can simply be told be compliant, we could begin to move forward. Otherwise, we're stuck where we are. Chris Angelico ___ 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: @@iterator in arguments object
As of ES5, apply doesn't require its 2nd arg to be a real array. An arguments object works fine there. Brendan Eich bren...@mozilla.com wrote: Wes Garland wrote: Arguments object is used here to fill the rest void, but also as an argument to apply (after converting into a real array) when writing wrapper functions; eg monkey patches, userspace profiling, etc. Is there an ES6 way to use apply on rest params? A rest parameter is a real Array instance. Function.prototype.apply works on array instances. What's the problem? /be If not, arguments must live on. Sent from my iPhone On 2012-12-23, at 12:48, Brandon Benvie bran...@brandonbenvie.com mailto:bran...@brandonbenvie.com wrote: Yeah good point, and you don't even need to dump all the named params. In light of this, I think its feasible to pronounce the arguments object in ES6 as vestigial and ready for retirement (except for all the legacy code of course). ES6 claims another victim: [object Arguments]. On Sunday, December 23, 2012, Brendan Eich wrote: You could always use an explicit rest parameter as the only formal parameter and still dispense with arguments in new code. ___ 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: @@iterator in arguments object
Here's one of the examples that was sticking out in my mind earlier that Brendan's solution takes care of. Array.prototype.reduce requires that if the initial value isn't provided then the first value of the array is the initial value. Using rest: function reduce(callback, ...initial){ var current, index; if (initial.length) { index = 0; current = initial[0]; } else { index = 1; current = this[0]; } ...etc... } Using arguments.length: function reduce(callback, initial){ var current, index; if (arguments.length 1) { index = 0; current = initial; } else { index = 1; current = this[0]; } ...etc... } I guess using rest like that is not a bad way to solve it, though it's not saying what you mean but rather kind of hacking around the limitation. Either way, it's certainly possible to forgo using arguments to accomplish the goal. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
On Sun, Dec 23, 2012 at 1:26 PM, Wes Garland w...@page.ca wrote: Arguments object is used here to fill the rest void, but also as an argument to apply (after converting into a real array) when writing wrapper functions; eg monkey patches, userspace profiling, etc. Is there an ES6 way to use apply on rest params? If not, arguments must live on. There is something really nice. You can use the ... operator when calling a function. For example, if you're wrapping a function foo: _origFoo = foo; foo = function (a, b, ...rest) { // ... do something ... return _origFoo(a, b, ...rest); }; If you're wrapping a method it's not quite as nice, but: _origMethod = Bar.prototype.method; Bar.prototype.method = function (a, b, ...rest) { // ... do something ... return _origMethod.call(this, a, b, ...rest); }; -j ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
Because initialValue can be a provided `undefined` in which case you would use that, as opposed to a missing value. The specification differentiates between a provided undefined and a lack of a parameter in a bunch of stdlib functions/methods. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
Er missing argument. The spec says If an initialValue was provided in the call to reduce, The fact that undefined is different from not provided is the reason you have to hack around with the argument count one way or another. On Sun, Dec 23, 2012 at 9:25 PM, Brandon Benvie bran...@brandonbenvie.comwrote: Because initialValue can be a provided `undefined` in which case you would use that, as opposed to a missing value. The specification differentiates between a provided undefined and a lack of a parameter in a bunch of stdlib functions/methods. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
On Dec 23, 2012, at 5:35 PM, Brandon Benvie wrote: Here's one of the examples that was sticking out in my mind earlier that Brendan's solution takes care of. Array.prototype.reduce requires that if the initial value isn't provided then the first value of the array is the initial value. Using rest: function reduce(callback, ...initial){ var current, index; if (initial.length) { index = 0; current = initial[0]; } else { index = 1; current = this[0]; } ...etc... } Using arguments.length: function reduce(callback, initial){ var current, index; if (arguments.length 1) { index = 0; current = initial; } else { index = 1; current = this[0]; } ...etc... } I guess using rest like that is not a bad way to solve it, though it's not saying what you mean but rather kind of hacking around the limitation. Either way, it's certainly possible to forgo using arguments to accomplish the goal. the way I would express this example is: function reduce(callback, ...rest){ var current, index; if (rest.length 0) { index = 0; current = rest[0]; } else { index = 1; current = this[0]; } ...etc... } which seems to exactly express the intent Allen ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
On Sun, Dec 23, 2012 at 9:25 PM, Brandon Benvie bran...@brandonbenvie.comwrote: Because initialValue can be a provided `undefined` in which case you would use that, as opposed to a missing value. The specification differentiates between a provided undefined and a lack of a parameter in a bunch of stdlib functions/methods. True enough: is present, used in reduce, reduceRight, Object.create and then elsewhere in the abstract internals and then in different contexts. Rick ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
That is an excellent solution! On Sun, Dec 23, 2012 at 10:46 PM, Axel Rauschmayer a...@rauschma.de wrote: How about the following solution? let missingArgument = {}; // or a symbol function reduce(callback, initial = missingArgument){ let startIndex; if (initial === missingArgument) { initial = this[0]; startIndex = 1; } else { startIndex = 0; } ...etc... } On Dec 24, 2012, at 3:32 , Allen Wirfs-Brock al...@wirfs-brock.com wrote: On Dec 23, 2012, at 5:35 PM, Brandon Benvie wrote: Here's one of the examples that was sticking out in my mind earlier that Brendan's solution takes care of. Array.prototype.reduce requires that if the initial value isn't provided then the first value of the array is the initial value. Using rest: function reduce(callback, ...initial){ var current, index; if (initial.length) { index = 0; current = initial[0]; } else { index = 1; current = this[0]; } ...etc... } the way I would express this example is: function reduce(callback, ...rest){ var current, index; if (rest.length 0) { index = 0; current = rest[0]; } else { index = 1; current = this[0]; } ...etc... } which seems to exactly express the intent -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
Thanks. The first `let` should be a `const`. On Dec 24, 2012, at 4:47 , Brandon Benvie bran...@brandonbenvie.com wrote: That is an excellent solution! On Sun, Dec 23, 2012 at 10:46 PM, Axel Rauschmayer a...@rauschma.de wrote: How about the following solution? let missingArgument = {}; // or a symbol function reduce(callback, initial = missingArgument){ let startIndex; if (initial === missingArgument) { initial = this[0]; startIndex = 1; } else { startIndex = 0; } ...etc... } On Dec 24, 2012, at 3:32 , Allen Wirfs-Brock al...@wirfs-brock.com wrote: On Dec 23, 2012, at 5:35 PM, Brandon Benvie wrote: Here's one of the examples that was sticking out in my mind earlier that Brendan's solution takes care of. Array.prototype.reduce requires that if the initial value isn't provided then the first value of the array is the initial value. Using rest: function reduce(callback, ...initial){ var current, index; if (initial.length) { index = 0; current = initial[0]; } else { index = 1; current = this[0]; } ...etc... } the way I would express this example is: function reduce(callback, ...rest){ var current, index; if (rest.length 0) { index = 0; current = rest[0]; } else { index = 1; current = this[0]; } ...etc... } which seems to exactly express the intent -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
Won't work for an explicitly pass undefined because that triggers assignment of the default value Axel Rauschmayer a...@rauschma.de wrote: How about the following solution? let missingArgument = {}; // or a symbol function reduce(callback, initial = missingArgument){ let startIndex; if (initial === missingArgument) { initial = this[0]; startIndex = 1; } else { startIndex = 0; } ...etc... } On Dec 24, 2012, at 3:32 , Allen Wirfs-Brock al...@wirfs-brock.com wrote: On Dec 23, 2012, at 5:35 PM, Brandon Benvie wrote: Here's one of the examples that was sticking out in my mind earlier that Brendan's solution takes care of. Array.prototype.reduce requires that if the initial value isn't provided then the first value of the array is the initial value. Using rest: function reduce(callback, ...initial){ var current, index; if (initial.length) { index = 0; current = initial[0]; } else { index = 1; current = this[0]; } ...etc... } the way I would express this example is: function reduce(callback, ...rest){ var current, index; if (rest.length 0) { index = 0; current = rest[0]; } else { index = 1; current = this[0]; } ...etc... } which seems to exactly express the intent -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
Ah yes, so default value can't do the job in any case where undefined is differentiated from missing, similar to how directly comparing the named binding to undefined can't differentiate either. On Sun, Dec 23, 2012 at 11:08 PM, Allen Wirfs-Brock al...@wirfs-brock.comwrote: Won't work for an explicitly pass undefined because that triggers assignment of the default value Axel Rauschmayer a...@rauschma.de wrote: How about the following solution? let missingArgument = {}; // or a symbol function reduce(callback, initial = missingArgument){ let startIndex; if (initial === missingArgument) { initial = this[0]; startIndex = 1; } else { startIndex = 0; } ...etc... } On Dec 24, 2012, at 3:32 , Allen Wirfs-Brock al...@wirfs-brock.com wrote: On Dec 23, 2012, at 5:35 PM, Brandon Benvie wrote: Here's one of the examples that was sticking out in my mind earlier that Brendan's solution takes care of. Array.prototype.reduce requires that if the initial value isn't provided then the first value of the array is the initial value. Using rest: function reduce(callback, ...initial){ var current, index; if (initial.length) { index = 0; current = initial[0]; } else { index = 1; current = this[0]; } ...etc... } the way I would express this example is: function reduce(callback, ...rest){ var current, index; if (rest.length 0) { index = 0; current = rest[0]; } else { index = 1; current = this[0]; } ...etc... } which seems to exactly express the intent -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
Ah damn, forgot about that discussion (combinatorial explosion etc.). On Dec 24, 2012, at 5:08 , Allen Wirfs-Brock al...@wirfs-brock.com wrote: Won't work for an explicitly pass undefined because that triggers assignment of the default value Axel Rauschmayer a...@rauschma.de wrote: How about the following solution? let missingArgument = {}; // or a symbol function reduce(callback, initial = missingArgument){ let startIndex; if (initial === missingArgument) { initial = this[0]; startIndex = 1; } else { startIndex = 0; } ...etc... } On Dec 24, 2012, at 3:32 , Allen Wirfs-Brock al...@wirfs-brock.com wrote: On Dec 23, 2012, at 5:35 PM, Brandon Benvie wrote: Here's one of the examples that was sticking out in my mind earlier that Brendan's solution takes care of. Array.prototype.reduce requires that if the initial value isn't provided then the first value of the array is the initial value. Using rest: function reduce(callback, ...initial){ var current, index; if (initial.length) { index = 0; current = initial[0]; } else { index = 1; current = this[0]; } ...etc... } the way I would express this example is: function reduce(callback, ...rest){ var current, index; if (rest.length 0) { index = 0; current = rest[0]; } else { index = 1; current = this[0]; } ...etc... } which seems to exactly express the intent -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
Welcome to my life... Axel Rauschmayer a...@rauschma.de wrote: Ah damn, forgot about that discussion (combinatorial explosion etc.). On Dec 24, 2012, at 5:08 , Allen Wirfs-Brock al...@wirfs-brock.com wrote: Won't work for an explicitly pass undefined because that triggers assignment of the default value Axel Rauschmayer a...@rauschma.de wrote: How about the following solution? let missingArgument = {}; // or a symbol function reduce(callback, initial = missingArgument){ let startIndex; if (initial === missingArgument) { initial = this[0]; startIndex = 1; } else { startIndex = 0; } ...etc... } On Dec 24, 2012, at 3:32 , Allen Wirfs-Brock al...@wirfs-brock.com wrote: On Dec 23, 2012, at 5:35 PM, Brandon Benvie wrote: Here's one of the examples that was sticking out in my mind earlier that Brendan's solution takes care of. Array.prototype.reduce requires that if the initial value isn't provided then the first value of the array is the initial value. Using rest: function reduce(callback, ...initial){ var current, index; if (initial.length) { index = 0; current = initial[0]; } else { index = 1; current = this[0]; } ...etc... } the way I would express this example is: function reduce(callback, ...rest){ var current, index; if (rest.length 0) { index = 0; current = rest[0]; } else { index = 1; current = this[0]; } ...etc... } which seems to exactly express the intent -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: @@iterator in arguments object
On Sun, Dec 23, 2012 at 10:46 PM, Axel Rauschmayer a...@rauschma.de wrote: How about the following solution? let missingArgument = {}; // or a symbol function reduce(callback, initial = missingArgument){ let startIndex; An explicit undefined will trigger the default value, in this case resulting in the missingArgument to be used See: https://mail.mozilla.org/pipermail/es-discuss/2012-July/024207.html Rick if (initial === missingArgument) { initial = this[0]; startIndex = 1; } else { startIndex = 0; } ...etc... } On Dec 24, 2012, at 3:32 , Allen Wirfs-Brock al...@wirfs-brock.com wrote: On Dec 23, 2012, at 5:35 PM, Brandon Benvie wrote: Here's one of the examples that was sticking out in my mind earlier that Brendan's solution takes care of. Array.prototype.reduce requires that if the initial value isn't provided then the first value of the array is the initial value. Using rest: function reduce(callback, ...initial){ var current, index; if (initial.length) { index = 0; current = initial[0]; } else { index = 1; current = this[0]; } ...etc... } the way I would express this example is: function reduce(callback, ...rest){ var current, index; if (rest.length 0) { index = 0; current = rest[0]; } else { index = 1; current = this[0]; } ...etc... } which seems to exactly express the intent -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com ___ 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