Ignoring arguments
You can already do it like this: ```js ((...[,,foo]) => foo)(1, 2, 3) // -> 3 ``` R. <http://untu.ms/> On Sun, May 29, 2016 at 6:53 PM, Cyril Auburtin <cyril.auburtin at gmail.com> wrote: > Similarly to: > > `var [,x,,y] = [1,2,3,4,5,6];` > > I think it could be interesting to let a field empty in function arguments > > `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` > > `function test(a,,b) { }` > > (but that would alter the current parsing, that doesn't allow it) > > Currently I often use `_` as a way to mark ignored fields, but when there > are more than 1 you need another identifier. A standard way would be > interesting rather > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160529/c38a07c5/attachment.html>
I'm quite sure this syntax is invalid.
I'm quite sure this syntax is invalid. On Sun, May 29, 2016 at 9:36 PM, Renki Ivanko <fatalis.erratum at gmail.com> wrote: > You can already do it like this: > > ```js > ((...[,,foo]) => foo)(1, 2, 3) // -> 3 > ``` > > > R. <http://untu.ms/> > > On Sun, May 29, 2016 at 6:53 PM, Cyril Auburtin <cyril.auburtin at gmail.com> > wrote: > >> Similarly to: >> >> `var [,x,,y] = [1,2,3,4,5,6];` >> >> I think it could be interesting to let a field empty in function arguments >> >> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >> >> `function test(a,,b) { }` >> >> (but that would alter the current parsing, that doesn't allow it) >> >> Currently I often use `_` as a way to mark ignored fields, but when there >> are more than 1 you need another identifier. A standard way would be >> interesting rather >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160529/d25184ae/attachment.html>
It works in V8 at least, so I assumed it's correct.
It works in V8 at least, so I assumed it's correct. On Sun, May 29, 2016 at 8:29 PM, Bob Myers <rtm at gol.com> wrote: > I'm quite sure this syntax is invalid. > > > On Sun, May 29, 2016 at 9:36 PM, Renki Ivanko <fatalis.erratum at gmail.com> > wrote: > >> You can already do it like this: >> >> ```js >> ((...[,,foo]) => foo)(1, 2, 3) // -> 3 >> ``` >> >> >> R. <http://untu.ms/> >> >> On Sun, May 29, 2016 at 6:53 PM, Cyril Auburtin <cyril.auburtin at gmail.com >> > wrote: >> >>> Similarly to: >>> >>> `var [,x,,y] = [1,2,3,4,5,6];` >>> >>> I think it could be interesting to let a field empty in function >>> arguments >>> >>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>> >>> `function test(a,,b) { }` >>> >>> (but that would alter the current parsing, that doesn't allow it) >>> >>> Currently I often use `_` as a way to mark ignored fields, but when >>> there are more than 1 you need another identifier. A standard way would be >>> interesting rather >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160529/1b826f43/attachment-0001.html>
You might think so, but you'd be wrong. Perfectly valid formal parameters
You might think so, but you'd be wrong. Perfectly valid formal parameters > On May 29, 2016, at 1:29 PM, Bob Myers <rtm at gol.com> wrote: > > I'm quite sure this syntax is invalid. > > >> On Sun, May 29, 2016 at 9:36 PM, Renki Ivanko <fatalis.erratum at gmail.com> wrote: >> You can already do it like this: >> >> ```js >> ((...[,,foo]) => foo)(1, 2, 3) // -> 3 >> ``` >> >> >> R. <http://untu.ms/> >> >>> On Sun, May 29, 2016 at 6:53 PM, Cyril Auburtin <cyril.auburtin at gmail.com> wrote: >>> Similarly to: >>> >>> `var [,x,,y] = [1,2,3,4,5,6];` >>> >>> I think it could be interesting to let a field empty in function arguments >>> >>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>> >>> `function test(a,,b) { }` >>> >>> (but that would alter the current parsing, that doesn't allow it) >>> >>> Currently I often use `_` as a way to mark ignored fields, but when there are more than 1 you need another identifier. A standard way would be interesting rather > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160529/48c75008/attachment.html>
It is. https://tc39.github.io/ecma262/#prod-FunctionRestParameter https://tc39.github.io/ecma262/#prod-BindingRestElement > On May 29, 2016, at 1:36 PM, Renki Ivanko <fatalis.erratum at gmail.com> wrote: > > It works in V8 at least, so I assumed it's correct. > >> On Sun, May 29, 2016 at 8:29 PM, Bob Myers <rtm at gol.com> wrote: >> I'm quite sure this syntax is invalid. >> >> >>> On Sun, May 29, 2016 at 9:36 PM, Renki Ivanko <fatalis.erratum at gmail.com> wrote: >>> You can already do it like this: >>> >>> ```js >>> ((...[,,foo]) => foo)(1, 2, 3) // -> 3 >>> ``` >>> >>> >>> R. <http://untu.ms/> >>> >>>> On Sun, May 29, 2016 at 6:53 PM, Cyril Auburtin <cyril.auburtin at gmail.com> wrote: >>>> Similarly to: >>>> >>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>> >>>> I think it could be interesting to let a field empty in function arguments >>>> >>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>>> >>>> `function test(a,,b) { }` >>>> >>>> (but that would alter the current parsing, that doesn't allow it) >>>> >>>> Currently I often use `_` as a way to mark ignored fields, but when there are more than 1 you need another identifier. A standard way would be interesting rather > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160529/1518c25c/attachment.html>
Eliding array elements is not "similar" to eliding function formal parameters. The latter is extremely rare, hardly readable, confusing, bug-prone, and unnecessary because there is already a "standard way" which is to use any old parameter name you want:
function foo(UNUSED1, UNUSED2, x)
Most linters will not complain, or there are ways to shut them up if they do.
If you want to throw away an argument, just throw it away.
function skipFirstParam(fn) { return ((first, ...args) => fn(...args)); }
[1,2,3,4].map(skipFirstParam(i => i));
Or use Renki's solution.
Bob
On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin <cyril.auburtin at gmail.com>
wrote:
Eliding array elements is not "similar" to eliding function formal parameters. The latter is extremely rare, hardly readable, confusing, bug-prone, and unnecessary because there is already a "standard way" which is to use any old parameter name you want: ```js function foo(UNUSED1, UNUSED2, x) ```` Most linters will not complain, or there are ways to shut them up if they do. If you want to throw away an argument, just throw it away. ```js function skipFirstParam(fn) { return ((first, ...args) => fn(...args)); } `[1,2,3,4].map(skipFirstParam(i => i)); ``` Or use Renki's solution. Bob On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin <cyril.auburtin at gmail.com> wrote: > Similarly to: > > `var [,x,,y] = [1,2,3,4,5,6];` > > I think it could be interesting to let a field empty in function arguments > > `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` > > `function test(a,,b) { }` > > (but that would alter the current parsing, that doesn't allow it) > > Currently I often use `_` as a way to mark ignored fields, but when there > are more than 1 you need another identifier. A standard way would be > interesting rather > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160529/0445cb0b/attachment.html>
function fn(...[a, b, c, ...rest]){}
is mostly no different than
function fn(...args){
let [a, b, c, ...rest] = args;
}
This wasn't officially allowed in ES2015, where only an Identifier was allowed as a rest param target in arguments, but the behavior has since been expanded to cover this case in ES2016: tc39/ecma262/commit/d322357e6be95bc4bd3e03f5944a736aac55fa50
Not that I think this example is particularly readable :)
``` function fn(...[a, b, c, ...rest]){} ``` is mostly no different than ``` function fn(...args){ let [a, b, c, ...rest] = args; } ``` This wasn't officially allowed in ES2015, where only an Identifier was allowed as a rest param target in arguments, but the behavior has since been expanded to cover this case in ES2016: https://github.com/tc39/ecma262/commit/d322357e6be95bc4bd3e03f5944a736aac55fa50 Not that I think this example is particularly readable :) On Sun, May 29, 2016 at 10:36 AM, Renki Ivanko <fatalis.erratum at gmail.com> wrote: > It works in V8 at least, so I assumed it's correct. > > On Sun, May 29, 2016 at 8:29 PM, Bob Myers <rtm at gol.com> wrote: > >> I'm quite sure this syntax is invalid. >> >> >> On Sun, May 29, 2016 at 9:36 PM, Renki Ivanko <fatalis.erratum at gmail.com> >> wrote: >> >>> You can already do it like this: >>> >>> ```js >>> ((...[,,foo]) => foo)(1, 2, 3) // -> 3 >>> ``` >>> >>> >>> R. <http://untu.ms/> >>> >>> On Sun, May 29, 2016 at 6:53 PM, Cyril Auburtin < >>> cyril.auburtin at gmail.com> wrote: >>> >>>> Similarly to: >>>> >>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>> >>>> I think it could be interesting to let a field empty in function >>>> arguments >>>> >>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>>> >>>> `function test(a,,b) { }` >>>> >>>> (but that would alter the current parsing, that doesn't allow it) >>>> >>>> Currently I often use `_` as a way to mark ignored fields, but when >>>> there are more than 1 you need another identifier. A standard way would be >>>> interesting rather >>>> >>> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160529/2af85ec9/attachment-0001.html>
You could stop with "rare"; having to make up unused names is an obvious smell in comparison.
foo(UNUSED1, UNUSED2, x)
foo(_, __, x)
foo(,, x)
foo(...[,, x])
The latter is shorter and more explicit and would not be any more confusing if it became common.
You could stop with "rare"; having to make up unused names is an obvious smell in comparison. ```js foo(UNUSED1, UNUSED2, x) foo(_, __, x) foo(,, x) foo(...[,, x]) ``` The latter is shorter and more explicit and would not be any more confusing if it became common. On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: > Eliding array elements is not "similar" to eliding function formal > parameters. The latter is extremely rare, hardly readable, confusing, > bug-prone, and unnecessary because there is already a "standard way" which > is to use any old parameter name you want: > > ```js > function foo(UNUSED1, UNUSED2, x) > ```` > > Most linters will not complain, or there are ways to shut them up if they > do. > > If you want to throw away an argument, just throw it away. > > ```js > function skipFirstParam(fn) { return ((first, ...args) => fn(...args)); } > > `[1,2,3,4].map(skipFirstParam(i => i)); > > ``` > > Or use Renki's solution. > > Bob > > > On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin <cyril.auburtin at gmail.com> > wrote: > >> Similarly to: >> >> `var [,x,,y] = [1,2,3,4,5,6];` >> >> I think it could be interesting to let a field empty in function arguments >> >> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >> >> `function test(a,,b) { }` >> >> (but that would alter the current parsing, that doesn't allow it) >> >> Currently I often use `_` as a way to mark ignored fields, but when there >> are more than 1 you need another identifier. A standard way would be >> interesting rather >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160529/9c32f1d1/attachment.html>
Since functions arguments is an array under the hood, they could 'more behave the same'
Both function arguments and arrays accept spreading: [1, 2, ...args]
and fn(1,2, ...args)
a function definition like (,i) => {}
, would be the equivalent of var [,i] = arguments
an invocation fn(,,i)
would be the equivalent of [,,i]
It's possible with (...[,i]) => {}, (_,i)=>{}
like Renki said, but slightly less simply
Are there possible issues with that 'extension' of function syntax?
Since functions arguments is an array under the hood, they could 'more behave the same' Both function arguments and arrays accept spreading: *[1, 2, ...args] * and *fn(1, 2, ...args)* a function definition like *(,i) => {}*, would be the equivalent of *var [,i] = arguments* an invocation *fn(,,i)* would be the equivalent of *[,,i]* It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, but slightly less simply Are there possible issues with that 'extension' of function syntax? 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: > You could stop with "rare"; having to make up unused names is an obvious > smell in comparison. > > ```js > foo(UNUSED1, UNUSED2, x) > > foo(_, __, x) > > foo(,, x) > > foo(...[,, x]) > ``` > > The latter is shorter and more explicit and would not be any more > confusing if it became common. > > > On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: > >> Eliding array elements is not "similar" to eliding function formal >> parameters. The latter is extremely rare, hardly readable, confusing, >> bug-prone, and unnecessary because there is already a "standard way" which >> is to use any old parameter name you want: >> >> ```js >> function foo(UNUSED1, UNUSED2, x) >> ```` >> >> Most linters will not complain, or there are ways to shut them up if they >> do. >> >> If you want to throw away an argument, just throw it away. >> >> ```js >> function skipFirstParam(fn) { return ((first, ...args) => fn(...args)); } >> >> `[1,2,3,4].map(skipFirstParam(i => i)); >> >> ``` >> >> Or use Renki's solution. >> >> Bob >> >> >> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin <cyril.auburtin at gmail.com >> > wrote: >> >>> Similarly to: >>> >>> `var [,x,,y] = [1,2,3,4,5,6];` >>> >>> I think it could be interesting to let a field empty in function >>> arguments >>> >>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>> >>> `function test(a,,b) { }` >>> >>> (but that would alter the current parsing, that doesn't allow it) >>> >>> Currently I often use `_` as a way to mark ignored fields, but when >>> there are more than 1 you need another identifier. A standard way would be >>> interesting rather >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160529/488ffa04/attachment.html>
One more similarity is that both function parameters and destructuring allow default values: (foo = 1) vs [foo = 1].
One more similarity is that both function parameters and destructuring allow default values: (foo = 1) vs [foo = 1]. On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin <cyril.auburtin at gmail.com> wrote: > Since functions arguments is an array under the hood, they could 'more > behave the same' > > Both function arguments and arrays accept spreading: *[1, 2, ...args] * > and *fn(1, 2, ...args)* > > a function definition like *(,i) => {}*, would be the equivalent of *var > [,i] = arguments* > > an invocation *fn(,,i)* would be the equivalent of *[,,i]* > > It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, but > slightly less simply > > Are there possible issues with that 'extension' of function syntax? > > > 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: > >> You could stop with "rare"; having to make up unused names is an obvious >> smell in comparison. >> >> ```js >> foo(UNUSED1, UNUSED2, x) >> >> foo(_, __, x) >> >> foo(,, x) >> >> foo(...[,, x]) >> ``` >> >> The latter is shorter and more explicit and would not be any more >> confusing if it became common. >> >> >> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >> >>> Eliding array elements is not "similar" to eliding function formal >>> parameters. The latter is extremely rare, hardly readable, confusing, >>> bug-prone, and unnecessary because there is already a "standard way" which >>> is to use any old parameter name you want: >>> >>> ```js >>> function foo(UNUSED1, UNUSED2, x) >>> ```` >>> >>> Most linters will not complain, or there are ways to shut them up if >>> they do. >>> >>> If you want to throw away an argument, just throw it away. >>> >>> ```js >>> function skipFirstParam(fn) { return ((first, ...args) => fn(...args)); } >>> >>> `[1,2,3,4].map(skipFirstParam(i => i)); >>> >>> ``` >>> >>> Or use Renki's solution. >>> >>> Bob >>> >>> >>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>> cyril.auburtin at gmail.com> wrote: >>> >>>> Similarly to: >>>> >>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>> >>>> I think it could be interesting to let a field empty in function >>>> arguments >>>> >>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>>> >>>> `function test(a,,b) { }` >>>> >>>> (but that would alter the current parsing, that doesn't allow it) >>>> >>>> Currently I often use `_` as a way to mark ignored fields, but when >>>> there are more than 1 you need another identifier. A standard way would be >>>> interesting rather >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160530/fc7eacdb/attachment.html>
Just bumping this up
Calling foo(1)
where foo is defined with 3 arguments, lets the 2 others
undefined, this behavior is already a bit magic and similar to the behavior
of an array, so I still think foo(a,,b,,,c) should be like
foo(...[a,,b,,,c])
Other example:
var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => undefined, 3 => 7} // here commas fantasies are allowed in arrays
m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // setting implicitely value as undefined
m.set(3, ) // not allowed, which should be m.set(...[3,]) or m.set(3, undefined)
and again, it would help for callbacks too, something( ( , , thirdArg) => {} )
I saw this jeffmo.github.io/es-trailing-function-commas, it seems like a sub-case
Just bumping this up Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 others undefined, this behavior is already a bit magic and similar to the behavior of an array, so I still think foo(a,,b,,,c) should be like foo(...[a,,b,,,c]) Other example: ``` var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => undefined, 3 => 7} // here commas fantasies are allowed in arrays m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // setting implicitely value as undefined m.set(3, ) // not allowed, which should be m.set(...[3,]) ``` and again, it would help for callbacks too, `something( ( , , thirdArg) => {} )` I saw this https://jeffmo.github.io/es-trailing-function-commas/, it seems like a sub-case 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: > One more similarity is that both function parameters and destructuring > allow default values: (foo = 1) vs [foo = 1]. > > > > On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin <cyril.auburtin at gmail.com > > wrote: > >> Since functions arguments is an array under the hood, they could 'more >> behave the same' >> >> Both function arguments and arrays accept spreading: *[1, 2, ...args] * >> and *fn(1, 2, ...args)* >> >> a function definition like *(,i) => {}*, would be the equivalent of *var >> [,i] = arguments* >> >> an invocation *fn(,,i)* would be the equivalent of *[,,i]* >> >> It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, but >> slightly less simply >> >> Are there possible issues with that 'extension' of function syntax? >> >> >> 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >> >>> You could stop with "rare"; having to make up unused names is an obvious >>> smell in comparison. >>> >>> ```js >>> foo(UNUSED1, UNUSED2, x) >>> >>> foo(_, __, x) >>> >>> foo(,, x) >>> >>> foo(...[,, x]) >>> ``` >>> >>> The latter is shorter and more explicit and would not be any more >>> confusing if it became common. >>> >>> >>> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >>> >>>> Eliding array elements is not "similar" to eliding function formal >>>> parameters. The latter is extremely rare, hardly readable, confusing, >>>> bug-prone, and unnecessary because there is already a "standard way" which >>>> is to use any old parameter name you want: >>>> >>>> ```js >>>> function foo(UNUSED1, UNUSED2, x) >>>> ```` >>>> >>>> Most linters will not complain, or there are ways to shut them up if >>>> they do. >>>> >>>> If you want to throw away an argument, just throw it away. >>>> >>>> ```js >>>> function skipFirstParam(fn) { return ((first, ...args) => fn(...args)); >>>> } >>>> >>>> `[1,2,3,4].map(skipFirstParam(i => i)); >>>> >>>> ``` >>>> >>>> Or use Renki's solution. >>>> >>>> Bob >>>> >>>> >>>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>>> cyril.auburtin at gmail.com> wrote: >>>> >>>>> Similarly to: >>>>> >>>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>>> >>>>> I think it could be interesting to let a field empty in function >>>>> arguments >>>>> >>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>>>> >>>>> `function test(a,,b) { }` >>>>> >>>>> (but that would alter the current parsing, that doesn't allow it) >>>>> >>>>> Currently I often use `_` as a way to mark ignored fields, but when >>>>> there are more than 1 you need another identifier. A standard way would be >>>>> interesting rather >>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160808/cfc81811/attachment-0001.html>
For what it's worth, elided array elements aren't available in strict mode
(they're a syntax error), and it's not likely anyone is going to want to
add a new sloppy mode only feature. Plus, it's not easy to tell at a glance
if it's a typo or intentional. Math.min(x,,y)
is a likely error, but a
syntax error is much more informative than NaN
or a very odd undefined
.
I don't see the point of not making it explicit.
For what it's worth, elided array elements aren't available in strict mode (they're a syntax error), and it's not likely anyone is going to want to add a new sloppy mode only feature. Plus, it's not easy to tell at a glance if it's a typo or intentional. `Math.min(x,,y)` is a likely error, but a syntax error is much more informative than `NaN` or a very odd `undefined`. I don't see the point of not making it explicit. On Mon, Aug 8, 2016, 06:34 Cyril Auburtin <cyril.auburtin at gmail.com> wrote: > Just bumping this up > > Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 others > undefined, this behavior is already a bit magic and similar to the behavior > of an array, so I still think foo(a,,b,,,c) should be like > foo(...[a,,b,,,c]) > > Other example: > ``` > var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => undefined, > 3 => 7} // here commas fantasies are allowed in arrays > m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // > setting implicitely value as undefined > m.set(3, ) // not allowed, which should be m.set(...[3,]) > ``` > > and again, it would help for callbacks too, `something( ( , , thirdArg) => > {} )` > > I saw this https://jeffmo.github.io/es-trailing-function-commas/, it > seems like a sub-case > > 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: > >> One more similarity is that both function parameters and destructuring >> allow default values: (foo = 1) vs [foo = 1]. >> >> >> >> On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin < >> cyril.auburtin at gmail.com> wrote: >> >>> Since functions arguments is an array under the hood, they could 'more >>> behave the same' >>> >>> Both function arguments and arrays accept spreading: *[1, 2, ...args] * >>> and *fn(1, 2, ...args)* >>> >>> a function definition like *(,i) => {}*, would be the equivalent of *var >>> [,i] = arguments* >>> >>> an invocation *fn(,,i)* would be the equivalent of *[,,i]* >>> >>> It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, but >>> slightly less simply >>> >>> Are there possible issues with that 'extension' of function syntax? >>> >>> >>> 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >>> >>>> You could stop with "rare"; having to make up unused names is an >>>> obvious smell in comparison. >>>> >>>> ```js >>>> foo(UNUSED1, UNUSED2, x) >>>> >>>> foo(_, __, x) >>>> >>>> foo(,, x) >>>> >>>> foo(...[,, x]) >>>> ``` >>>> >>>> The latter is shorter and more explicit and would not be any more >>>> confusing if it became common. >>>> >>>> >>>> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >>>> >>>>> Eliding array elements is not "similar" to eliding function formal >>>>> parameters. The latter is extremely rare, hardly readable, confusing, >>>>> bug-prone, and unnecessary because there is already a "standard way" which >>>>> is to use any old parameter name you want: >>>>> >>>>> ```js >>>>> function foo(UNUSED1, UNUSED2, x) >>>>> ```` >>>>> >>>>> Most linters will not complain, or there are ways to shut them up if >>>>> they do. >>>>> >>>>> If you want to throw away an argument, just throw it away. >>>>> >>>>> ```js >>>>> function skipFirstParam(fn) { return ((first, ...args) => >>>>> fn(...args)); } >>>>> >>>>> `[1,2,3,4].map(skipFirstParam(i => i)); >>>>> >>>>> ``` >>>>> >>>>> Or use Renki's solution. >>>>> >>>>> Bob >>>>> >>>>> >>>>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>>>> cyril.auburtin at gmail.com> wrote: >>>>> >>>>>> Similarly to: >>>>>> >>>>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>>>> >>>>>> I think it could be interesting to let a field empty in function >>>>>> arguments >>>>>> >>>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>>>>> >>>>>> `function test(a,,b) { }` >>>>>> >>>>>> (but that would alter the current parsing, that doesn't allow it) >>>>>> >>>>>> Currently I often use `_` as a way to mark ignored fields, but when >>>>>> there are more than 1 you need another identifier. A standard way would be >>>>>> interesting rather >>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>> >>> >> > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160810/0db4ad76/attachment.html>
Le 10 août 2016 à 11:01, Isiah Meadows <isiahmeadows at gmail.com> a écrit :
For what it's worth, elided array elements aren't available in strict mode
Are you sure?
> Le 10 août 2016 à 11:01, Isiah Meadows <isiahmeadows at gmail.com> a écrit : > > For what it's worth, elided array elements aren't available in strict mode > Are you sure? —Claude -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160810/9a9d7624/attachment.html>
Okay. I'll admit I'm wrong here. I misremembered. I knew they were more of a legacy thing, I just didn't know they were available in strict mode.
Okay. I'll admit I'm wrong here. I misremembered. I knew they were more of a legacy thing, I just didn't know they were available in strict mode. On Wed, Aug 10, 2016, 05:37 Claude Pache <claude.pache at gmail.com> wrote: > Le 10 août 2016 à 11:01, Isiah Meadows <isiahmeadows at gmail.com> a écrit : > > For what it's worth, elided array elements aren't available in strict mode > > Are you sure? > > —Claude > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160810/a532d803/attachment.html>
What if you could use a .
as a wildcard? I don’t think it would conflict with existing syntax, and it would avoid binding a usable identifier. It would be more obvious than nothing between the commas.
What if you could use a `.` as a wildcard? I don’t think it would conflict with existing syntax, and it would avoid binding a usable identifier. It would be more obvious than nothing between the commas. > On Aug 8, 2016, at 06:33, Cyril Auburtin <cyril.auburtin at gmail.com> wrote: > > Just bumping this up > > Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 others undefined, this behavior is already a bit magic and similar to the behavior of an array, so I still think foo(a,,b,,,c) should be like foo(...[a,,b,,,c]) > > Other example: > ``` > var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => undefined, 3 => 7} // here commas fantasies are allowed in arrays > m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // setting implicitely value as undefined > m.set(3, ) // not allowed, which should be m.set(...[3,]) > ``` > > and again, it would help for callbacks too, `something( ( , , thirdArg) => {} )` > > I saw this https://jeffmo.github.io/es-trailing-function-commas/ <https://jeffmo.github.io/es-trailing-function-commas/>, it seems like a sub-case > > 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com <mailto:fatalis.erratum at gmail.com>>: > One more similarity is that both function parameters and destructuring allow default values: (foo = 1) vs [foo = 1]. > > > > On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin <cyril.auburtin at gmail.com <mailto:cyril.auburtin at gmail.com>> wrote: > Since functions arguments is an array under the hood, they could 'more behave the same' > > Both function arguments and arrays accept spreading: [1, 2, ...args] and fn(1, 2, ...args) > > a function definition like (,i) => {}, would be the equivalent of var [,i] = arguments > > an invocation fn(,,i) would be the equivalent of [,,i] > > It's possible with (...[,i]) => {}, (_,i)=>{} like Renki said, but slightly less simply > > Are there possible issues with that 'extension' of function syntax? > > > 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com <mailto:fatalis.erratum at gmail.com>>: > You could stop with "rare"; having to make up unused names is an obvious smell in comparison. > > ```js > foo(UNUSED1, UNUSED2, x) > > foo(_, __, x) > > foo(,, x) > > foo(...[,, x]) > ``` > > The latter is shorter and more explicit and would not be any more confusing if it became common. > > > On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com <mailto:rtm at gol.com>> wrote: > Eliding array elements is not "similar" to eliding function formal parameters. The latter is extremely rare, hardly readable, confusing, bug-prone, and unnecessary because there is already a "standard way" which is to use any old parameter name you want: > > ```js > function foo(UNUSED1, UNUSED2, x) > ```` > > Most linters will not complain, or there are ways to shut them up if they do. > > If you want to throw away an argument, just throw it away. > > ```js > function skipFirstParam(fn) { return ((first, ...args) => fn(...args)); } > > `[1,2,3,4].map(skipFirstParam(i => i)); > > ``` > > Or use Renki's solution. > > Bob > > > On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin <cyril.auburtin at gmail.com <mailto:cyril.auburtin at gmail.com>> wrote: > Similarly to: > > `var [,x,,y] = [1,2,3,4,5,6];` > > I think it could be interesting to let a field empty in function arguments > > `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` > > `function test(a,,b) { }` > > (but that would alter the current parsing, that doesn't allow it) > > Currently I often use `_` as a way to mark ignored fields, but when there are more than 1 you need another identifier. A standard way would be interesting rather > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> > https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> > https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> > > > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160810/e234f690/attachment-0001.html>
Confused by this thread.
What if you could use a
.
as a wildcard?
You can already use _
or anything you want, as was already pointed out in
early iterations of this idea.
it would avoid binding a usable identifier.
What is the problem with that?
What is the problem that this proposal is trying to solve? Any chance we could move on?
Bob
Confused by this thread. > What if you could use a `.` as a wildcard? You can already use `_` or anything you want, as was already pointed out in early iterations of this idea. > it would avoid binding a usable identifier. What is the problem with that? What is the problem that this proposal is trying to solve? Any chance we could move on? Bob On Wed, Aug 10, 2016 at 7:48 PM, Alan Johnson <alan at breakrs.com> wrote: > What if you could use a `.` as a wildcard? I don’t think it would conflict > with existing syntax, and it would avoid binding a usable identifier. It > would be more obvious than nothing between the commas. > > > On Aug 8, 2016, at 06:33, Cyril Auburtin <cyril.auburtin at gmail.com> wrote: > > Just bumping this up > > Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 others > undefined, this behavior is already a bit magic and similar to the behavior > of an array, so I still think foo(a,,b,,,c) should be like > foo(...[a,,b,,,c]) > > Other example: > ``` > var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => undefined, > 3 => 7} // here commas fantasies are allowed in arrays > m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // > setting implicitely value as undefined > m.set(3, ) // not allowed, which should be m.set(...[3,]) > ``` > > and again, it would help for callbacks too, `something( ( , , thirdArg) => > {} )` > > I saw this https://jeffmo.github.io/es-trailing-function-commas/, it > seems like a sub-case > > 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: > >> One more similarity is that both function parameters and destructuring >> allow default values: (foo = 1) vs [foo = 1]. >> >> >> >> On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin < >> cyril.auburtin at gmail.com> wrote: >> >>> Since functions arguments is an array under the hood, they could 'more >>> behave the same' >>> >>> Both function arguments and arrays accept spreading: *[1, 2, ...args] * >>> and *fn(1, 2, ...args)* >>> >>> a function definition like *(,i) => {}*, would be the equivalent of *var >>> [,i] = arguments* >>> >>> an invocation *fn(,,i)* would be the equivalent of *[,,i]* >>> >>> It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, but >>> slightly less simply >>> >>> Are there possible issues with that 'extension' of function syntax? >>> >>> >>> 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >>> >>>> You could stop with "rare"; having to make up unused names is an >>>> obvious smell in comparison. >>>> >>>> ```js >>>> foo(UNUSED1, UNUSED2, x) >>>> >>>> foo(_, __, x) >>>> >>>> foo(,, x) >>>> >>>> foo(...[,, x]) >>>> ``` >>>> >>>> The latter is shorter and more explicit and would not be any more >>>> confusing if it became common. >>>> >>>> >>>> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >>>> >>>>> Eliding array elements is not "similar" to eliding function formal >>>>> parameters. The latter is extremely rare, hardly readable, confusing, >>>>> bug-prone, and unnecessary because there is already a "standard way" which >>>>> is to use any old parameter name you want: >>>>> >>>>> ```js >>>>> function foo(UNUSED1, UNUSED2, x) >>>>> ```` >>>>> >>>>> Most linters will not complain, or there are ways to shut them up if >>>>> they do. >>>>> >>>>> If you want to throw away an argument, just throw it away. >>>>> >>>>> ```js >>>>> function skipFirstParam(fn) { return ((first, ...args) => >>>>> fn(...args)); } >>>>> >>>>> `[1,2,3,4].map(skipFirstParam(i => i)); >>>>> >>>>> ``` >>>>> >>>>> Or use Renki's solution. >>>>> >>>>> Bob >>>>> >>>>> >>>>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>>>> cyril.auburtin at gmail.com> wrote: >>>>> >>>>>> Similarly to: >>>>>> >>>>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>>>> >>>>>> I think it could be interesting to let a field empty in function >>>>>> arguments >>>>>> >>>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>>>>> >>>>>> `function test(a,,b) { }` >>>>>> >>>>>> (but that would alter the current parsing, that doesn't allow it) >>>>>> >>>>>> Currently I often use `_` as a way to mark ignored fields, but when >>>>>> there are more than 1 you need another identifier. A standard way would be >>>>>> interesting rather >>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>> >>> >> > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160810/196e7a7a/attachment.html>
Confused by this thread.
It's quite simple though, _ would be a useless allocated variable, you can't have more than 1, ...
What is the problem that this proposal is trying to solve?
ignoring/skipping argument in functions declarations (indeed the invocations could be let apart)
Math.min(x,,y)
yes this kind of thing would give NaN, that's why you can write it with more spaces to avoid a typo mistake Math.min(x, , y)
, but indeed you could
still have something like Math.min(x, /*y (no longer used)*/ , z)
. Like said
above, I realize the function invocations are sensible.
So, it could be only for function declarations
div.addEventListener('click', () => { } )
says to skip all arguments, and your callback scope is free of any additional vars
arr.forEach( x => { } )
or arr.forEach( (x) => { } )
says to only consider first argument, others are skipped, and not in scope
Array.from({length: 19}, (, i) => i )
would be similar for the second argument, similarly to array destructuring. It's not just for saving one character, that's really not the matter, it's for standardizing this way, because some people use _
, some don't, .... (Yes .
would even be better than a variable name like _
, something similar to Haskell's 'holes')
> Confused by this thread. It's quite simple though, _ would be a useless allocated variable, you an't have more than 1, ... > What is the problem that this proposal is trying to solve? ignoring/skipping argument in functions declarations (indeed the invocations could be let apart) > `Math.min(x,,y)` yes this kind of thing would give NaN, that's why you can `Math.min(x, , y)` write it with more spaces to avoid a typo mistake, indeed you could still have like `Math.min(x, /*y (no longer used)*/ , z)` would. Like said above, I realize the function invocations are sensible. So, it would be only for function declarations `div.addEventListener('click', () => { } )` says to skip all arguments, and you've your callback scope is free of any additional vars `arr.forEach( x => { } )` says to only consider first argument, others are skipped, and not in scope `Array.from({length: 19}, (, i) => i )` would be similar for the second argument, similarly to array destructuring. It's not just for saving one character, that's really not the matter, it's for standardizing this way, because some people use `_`, some don't, .... 2016-08-10 16:27 GMT+02:00 Bob Myers <rtm at gol.com>: > Confused by this thread. > > > What if you could use a `.` as a wildcard? > > You can already use `_` or anything you want, as was already pointed out > in early iterations of this idea. > > > it would avoid binding a usable identifier. > > What is the problem with that? > > What is the problem that this proposal is trying to solve? Any chance we > could move on? > > Bob > > > > On Wed, Aug 10, 2016 at 7:48 PM, Alan Johnson <alan at breakrs.com> wrote: > >> What if you could use a `.` as a wildcard? I don’t think it would >> conflict with existing syntax, and it would avoid binding a usable >> identifier. It would be more obvious than nothing between the commas. >> >> >> On Aug 8, 2016, at 06:33, Cyril Auburtin <cyril.auburtin at gmail.com> >> wrote: >> >> Just bumping this up >> >> Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 others >> undefined, this behavior is already a bit magic and similar to the behavior >> of an array, so I still think foo(a,,b,,,c) should be like >> foo(...[a,,b,,,c]) >> >> Other example: >> ``` >> var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => undefined, >> 3 => 7} // here commas fantasies are allowed in arrays >> m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // >> setting implicitely value as undefined >> m.set(3, ) // not allowed, which should be m.set(...[3,]) >> ``` >> >> and again, it would help for callbacks too, `something( ( , , thirdArg) >> => {} )` >> >> I saw this https://jeffmo.github.io/es-trailing-function-commas/, it >> seems like a sub-case >> >> 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >> >>> One more similarity is that both function parameters and destructuring >>> allow default values: (foo = 1) vs [foo = 1]. >>> >>> >>> >>> On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin < >>> cyril.auburtin at gmail.com> wrote: >>> >>>> Since functions arguments is an array under the hood, they could 'more >>>> behave the same' >>>> >>>> Both function arguments and arrays accept spreading: *[1, 2, ...args] * >>>> and *fn(1, 2, ...args)* >>>> >>>> a function definition like *(,i) => {}*, would be the equivalent of *var >>>> [,i] = arguments* >>>> >>>> an invocation *fn(,,i)* would be the equivalent of *[,,i]* >>>> >>>> It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, but >>>> slightly less simply >>>> >>>> Are there possible issues with that 'extension' of function syntax? >>>> >>>> >>>> 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >>>> >>>>> You could stop with "rare"; having to make up unused names is an >>>>> obvious smell in comparison. >>>>> >>>>> ```js >>>>> foo(UNUSED1, UNUSED2, x) >>>>> >>>>> foo(_, __, x) >>>>> >>>>> foo(,, x) >>>>> >>>>> foo(...[,, x]) >>>>> ``` >>>>> >>>>> The latter is shorter and more explicit and would not be any more >>>>> confusing if it became common. >>>>> >>>>> >>>>> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >>>>> >>>>>> Eliding array elements is not "similar" to eliding function formal >>>>>> parameters. The latter is extremely rare, hardly readable, confusing, >>>>>> bug-prone, and unnecessary because there is already a "standard way" which >>>>>> is to use any old parameter name you want: >>>>>> >>>>>> ```js >>>>>> function foo(UNUSED1, UNUSED2, x) >>>>>> ```` >>>>>> >>>>>> Most linters will not complain, or there are ways to shut them up if >>>>>> they do. >>>>>> >>>>>> If you want to throw away an argument, just throw it away. >>>>>> >>>>>> ```js >>>>>> function skipFirstParam(fn) { return ((first, ...args) => >>>>>> fn(...args)); } >>>>>> >>>>>> `[1,2,3,4].map(skipFirstParam(i => i)); >>>>>> >>>>>> ``` >>>>>> >>>>>> Or use Renki's solution. >>>>>> >>>>>> Bob >>>>>> >>>>>> >>>>>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>>>>> cyril.auburtin at gmail.com> wrote: >>>>>> >>>>>>> Similarly to: >>>>>>> >>>>>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>>>>> >>>>>>> I think it could be interesting to let a field empty in function >>>>>>> arguments >>>>>>> >>>>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>>>>>> >>>>>>> `function test(a,,b) { }` >>>>>>> >>>>>>> (but that would alter the current parsing, that doesn't allow it) >>>>>>> >>>>>>> Currently I often use `_` as a way to mark ignored fields, but when >>>>>>> there are more than 1 you need another identifier. A standard way would be >>>>>>> interesting rather >>>>>>> >>>>>>> _______________________________________________ >>>>>>> es-discuss mailing list >>>>>>> es-discuss at mozilla.org >>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>> >>>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>>> >>>>> >>>> >>> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160811/779748d9/attachment-0001.html>
ignoring/skipping argument in functions declarations (indeed the invocations could be let apart)
I am of the opinion that this is not a problem that needs to be solved at the language standardization level. The commas (or really any separator) for "skipping" a parameter looks like a mistake and is unintuitive (it's certainly not obvious to me what its intent is had I seen it without the context of this thread).
This seems like a problem solved with better coding practices. I typically make required parameters first and then any optional ones in a separate, single parameter called options. Callbacks can be done with chaining / promises / I fmake them required / etc. Skipping callbacks usually isn't a good idea. We could talk all day about who's coding practice is better than who's but ultimately this problem should be solved by developing / adopting good coding practices.
(Honestly I'm not a fan of the skipping in arrays either but considering it's an array I feel like it's at least a magnitude less confusing than doing it with function parameters)
> > ignoring/skipping argument in functions declarations (indeed the > invocations could be let apart) I am of the opinion that this is not a problem that needs to be solved at the language standardization level. The commas (or really any separator) for "skipping" a parameter looks like a mistake and is unintuitive (it's certainly not obvious to me what its intent is had I seen it without the context of this thread). This seems like a problem solved with better coding practices. I typically make required parameters first and then any optional ones in a separate, single parameter called options. Callbacks can be done with chaining / promises / I fmake them required / etc. Skipping callbacks usually isn't a good idea. We could talk all day about who's coding practice is better than who's but ultimately this problem should be solved by developing / adopting good coding practices. (Honestly I'm not a fan of the skipping in arrays either but considering it's an array I feel like it's at least a magnitude less confusing than doing it with function parameters) On Thu, Aug 11, 2016 at 4:00 AM, Cyril Auburtin <cyril.auburtin at gmail.com> wrote: > > Confused by this thread. > > It's quite simple though, _ would be a useless allocated variable, you > an't have more than 1, ... > > > What is the problem that this proposal is trying to solve? > > ignoring/skipping argument in functions declarations (indeed the > invocations could be let apart) > > > `Math.min(x,,y)` > > yes this kind of thing would give NaN, that's why you can `Math.min(x, , > y)` write it with more spaces to avoid a typo mistake, indeed you could > still have like `Math.min(x, /*y (no longer used)*/ , z)` would. Like > said above, I realize the function invocations are sensible. > > So, it would be only for function declarations > > `div.addEventListener('click', () => { } )` says to skip all arguments, > and you've your callback scope is free of any additional vars > > `arr.forEach( x => { } )` says to only consider first argument, others are > skipped, and not in scope > > `Array.from({length: 19}, (, i) => i )` would be similar for the second > argument, similarly to array destructuring. It's not just for saving one > character, that's really not the matter, it's for standardizing this way, > because some people use `_`, some don't, .... > > 2016-08-10 16:27 GMT+02:00 Bob Myers <rtm at gol.com>: > >> Confused by this thread. >> >> > What if you could use a `.` as a wildcard? >> >> You can already use `_` or anything you want, as was already pointed out >> in early iterations of this idea. >> >> > it would avoid binding a usable identifier. >> >> What is the problem with that? >> >> What is the problem that this proposal is trying to solve? Any chance we >> could move on? >> >> Bob >> >> >> >> On Wed, Aug 10, 2016 at 7:48 PM, Alan Johnson <alan at breakrs.com> wrote: >> >>> What if you could use a `.` as a wildcard? I don’t think it would >>> conflict with existing syntax, and it would avoid binding a usable >>> identifier. It would be more obvious than nothing between the commas. >>> >>> >>> On Aug 8, 2016, at 06:33, Cyril Auburtin <cyril.auburtin at gmail.com> >>> wrote: >>> >>> Just bumping this up >>> >>> Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 >>> others undefined, this behavior is already a bit magic and similar to the >>> behavior of an array, so I still think foo(a,,b,,,c) should be like >>> foo(...[a,,b,,,c]) >>> >>> Other example: >>> ``` >>> var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => >>> undefined, 3 => 7} // here commas fantasies are allowed in arrays >>> m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // >>> setting implicitely value as undefined >>> m.set(3, ) // not allowed, which should be m.set(...[3,]) >>> ``` >>> >>> and again, it would help for callbacks too, `something( ( , , thirdArg) >>> => {} )` >>> >>> I saw this https://jeffmo.github.io/es-trailing-function-commas/, it >>> seems like a sub-case >>> >>> 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >>> >>>> One more similarity is that both function parameters and destructuring >>>> allow default values: (foo = 1) vs [foo = 1]. >>>> >>>> >>>> >>>> On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin < >>>> cyril.auburtin at gmail.com> wrote: >>>> >>>>> Since functions arguments is an array under the hood, they could 'more >>>>> behave the same' >>>>> >>>>> Both function arguments and arrays accept spreading: *[1, 2, >>>>> ...args] * and *fn(1, 2, ...args)* >>>>> >>>>> a function definition like *(,i) => {}*, would be the equivalent of *var >>>>> [,i] = arguments* >>>>> >>>>> an invocation *fn(,,i)* would be the equivalent of *[,,i]* >>>>> >>>>> It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, but >>>>> slightly less simply >>>>> >>>>> Are there possible issues with that 'extension' of function syntax? >>>>> >>>>> >>>>> 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >>>>> >>>>>> You could stop with "rare"; having to make up unused names is an >>>>>> obvious smell in comparison. >>>>>> >>>>>> ```js >>>>>> foo(UNUSED1, UNUSED2, x) >>>>>> >>>>>> foo(_, __, x) >>>>>> >>>>>> foo(,, x) >>>>>> >>>>>> foo(...[,, x]) >>>>>> ``` >>>>>> >>>>>> The latter is shorter and more explicit and would not be any more >>>>>> confusing if it became common. >>>>>> >>>>>> >>>>>> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >>>>>> >>>>>>> Eliding array elements is not "similar" to eliding function formal >>>>>>> parameters. The latter is extremely rare, hardly readable, confusing, >>>>>>> bug-prone, and unnecessary because there is already a "standard way" which >>>>>>> is to use any old parameter name you want: >>>>>>> >>>>>>> ```js >>>>>>> function foo(UNUSED1, UNUSED2, x) >>>>>>> ```` >>>>>>> >>>>>>> Most linters will not complain, or there are ways to shut them up if >>>>>>> they do. >>>>>>> >>>>>>> If you want to throw away an argument, just throw it away. >>>>>>> >>>>>>> ```js >>>>>>> function skipFirstParam(fn) { return ((first, ...args) => >>>>>>> fn(...args)); } >>>>>>> >>>>>>> `[1,2,3,4].map(skipFirstParam(i => i)); >>>>>>> >>>>>>> ``` >>>>>>> >>>>>>> Or use Renki's solution. >>>>>>> >>>>>>> Bob >>>>>>> >>>>>>> >>>>>>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>>>>>> cyril.auburtin at gmail.com> wrote: >>>>>>> >>>>>>>> Similarly to: >>>>>>>> >>>>>>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>>>>>> >>>>>>>> I think it could be interesting to let a field empty in function >>>>>>>> arguments >>>>>>>> >>>>>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>>>>>>> >>>>>>>> `function test(a,,b) { }` >>>>>>>> >>>>>>>> (but that would alter the current parsing, that doesn't allow it) >>>>>>>> >>>>>>>> Currently I often use `_` as a way to mark ignored fields, but when >>>>>>>> there are more than 1 you need another identifier. A standard way would be >>>>>>>> interesting rather >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> es-discuss mailing list >>>>>>>> es-discuss at mozilla.org >>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> es-discuss mailing list >>>>>>> es-discuss at mozilla.org >>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160811/1a7448c8/attachment.html>
If you're talking about ignored function parameters in a declaration or
expression, much like _
in several functional languages (like Haskell and
Scala), I could see value in that. I'd prefer an explicit token for that,
though, something like this:
// ImmutableJS: convert map to list, only
// keeping values with integer keys
map
.filter((*, key) => typeof key === "number" && key % 1 === 0)
.toList()
If you're talking about ignored function parameters in a declaration or expression, much like `_` in several functional languages (like Haskell and Scala), I could see value in that. I'd prefer an explicit token for that, though, something like this: ```js // ImmutableJS: convert map to list, only // keeping values with integer keys map .filter((*, key) => typeof key === "number" && key % 1 === 0) .toList() ``` On Thu, Aug 11, 2016, 12:51 Kris Siegel <krissiegel at gmail.com> wrote: > ignoring/skipping argument in functions declarations (indeed the >> invocations could be let apart) > > > I am of the opinion that this is not a problem that needs to be solved at > the language standardization level. The commas (or really any separator) > for "skipping" a parameter looks like a mistake and is unintuitive (it's > certainly not obvious to me what its intent is had I seen it without the > context of this thread). > > This seems like a problem solved with better coding practices. I typically > make required parameters first and then any optional ones in a separate, > single parameter called options. Callbacks can be done with chaining / > promises / I fmake them required / etc. Skipping callbacks usually isn't a > good idea. We could talk all day about who's coding practice is better than > who's but ultimately this problem should be solved by developing / adopting > good coding practices. > > (Honestly I'm not a fan of the skipping in arrays either but considering > it's an array I feel like it's at least a magnitude less confusing than > doing it with function parameters) > > On Thu, Aug 11, 2016 at 4:00 AM, Cyril Auburtin <cyril.auburtin at gmail.com> > wrote: > >> > Confused by this thread. >> >> It's quite simple though, _ would be a useless allocated variable, you >> an't have more than 1, ... >> >> > What is the problem that this proposal is trying to solve? >> >> ignoring/skipping argument in functions declarations (indeed the >> invocations could be let apart) >> >> > `Math.min(x,,y)` >> >> yes this kind of thing would give NaN, that's why you can `Math.min(x, , >> y)` write it with more spaces to avoid a typo mistake, indeed you could >> still have like `Math.min(x, /*y (no longer used)*/ , z)` would. Like >> said above, I realize the function invocations are sensible. >> >> So, it would be only for function declarations >> >> `div.addEventListener('click', () => { } )` says to skip all arguments, >> and you've your callback scope is free of any additional vars >> >> `arr.forEach( x => { } )` says to only consider first argument, others >> are skipped, and not in scope >> >> `Array.from({length: 19}, (, i) => i )` would be similar for the second >> argument, similarly to array destructuring. It's not just for saving one >> character, that's really not the matter, it's for standardizing this way, >> because some people use `_`, some don't, .... >> >> 2016-08-10 16:27 GMT+02:00 Bob Myers <rtm at gol.com>: >> >>> Confused by this thread. >>> >>> > What if you could use a `.` as a wildcard? >>> >>> You can already use `_` or anything you want, as was already pointed out >>> in early iterations of this idea. >>> >>> > it would avoid binding a usable identifier. >>> >>> What is the problem with that? >>> >>> What is the problem that this proposal is trying to solve? Any chance we >>> could move on? >>> >>> Bob >>> >>> >>> >>> On Wed, Aug 10, 2016 at 7:48 PM, Alan Johnson <alan at breakrs.com> wrote: >>> >>>> What if you could use a `.` as a wildcard? I don’t think it would >>>> conflict with existing syntax, and it would avoid binding a usable >>>> identifier. It would be more obvious than nothing between the commas. >>>> >>>> >>>> On Aug 8, 2016, at 06:33, Cyril Auburtin <cyril.auburtin at gmail.com> >>>> wrote: >>>> >>>> Just bumping this up >>>> >>>> Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 >>>> others undefined, this behavior is already a bit magic and similar to the >>>> behavior of an array, so I still think foo(a,,b,,,c) should be like >>>> foo(...[a,,b,,,c]) >>>> >>>> Other example: >>>> ``` >>>> var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => >>>> undefined, 3 => 7} // here commas fantasies are allowed in arrays >>>> m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // >>>> setting implicitely value as undefined >>>> m.set(3, ) // not allowed, which should be m.set(...[3,]) >>>> ``` >>>> >>>> and again, it would help for callbacks too, `something( ( , , thirdArg) >>>> => {} )` >>>> >>>> I saw this https://jeffmo.github.io/es-trailing-function-commas/, it >>>> seems like a sub-case >>>> >>>> 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >>>> >>>>> One more similarity is that both function parameters and destructuring >>>>> allow default values: (foo = 1) vs [foo = 1]. >>>>> >>>>> >>>>> >>>>> On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin < >>>>> cyril.auburtin at gmail.com> wrote: >>>>> >>>>>> Since functions arguments is an array under the hood, they could >>>>>> 'more behave the same' >>>>>> >>>>>> Both function arguments and arrays accept spreading: *[1, 2, >>>>>> ...args] * and *fn(1, 2, ...args)* >>>>>> >>>>>> a function definition like *(,i) => {}*, would be the equivalent of *var >>>>>> [,i] = arguments* >>>>>> >>>>>> an invocation *fn(,,i)* would be the equivalent of *[,,i]* >>>>>> >>>>>> It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, but >>>>>> slightly less simply >>>>>> >>>>>> Are there possible issues with that 'extension' of function syntax? >>>>>> >>>>>> >>>>>> 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >>>>>> >>>>>>> You could stop with "rare"; having to make up unused names is an >>>>>>> obvious smell in comparison. >>>>>>> >>>>>>> ```js >>>>>>> foo(UNUSED1, UNUSED2, x) >>>>>>> >>>>>>> foo(_, __, x) >>>>>>> >>>>>>> foo(,, x) >>>>>>> >>>>>>> foo(...[,, x]) >>>>>>> ``` >>>>>>> >>>>>>> The latter is shorter and more explicit and would not be any more >>>>>>> confusing if it became common. >>>>>>> >>>>>>> >>>>>>> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >>>>>>> >>>>>>>> Eliding array elements is not "similar" to eliding function formal >>>>>>>> parameters. The latter is extremely rare, hardly readable, confusing, >>>>>>>> bug-prone, and unnecessary because there is already a "standard way" which >>>>>>>> is to use any old parameter name you want: >>>>>>>> >>>>>>>> ```js >>>>>>>> function foo(UNUSED1, UNUSED2, x) >>>>>>>> ```` >>>>>>>> >>>>>>>> Most linters will not complain, or there are ways to shut them up >>>>>>>> if they do. >>>>>>>> >>>>>>>> If you want to throw away an argument, just throw it away. >>>>>>>> >>>>>>>> ```js >>>>>>>> function skipFirstParam(fn) { return ((first, ...args) => >>>>>>>> fn(...args)); } >>>>>>>> >>>>>>>> `[1,2,3,4].map(skipFirstParam(i => i)); >>>>>>>> >>>>>>>> ``` >>>>>>>> >>>>>>>> Or use Renki's solution. >>>>>>>> >>>>>>>> Bob >>>>>>>> >>>>>>>> >>>>>>>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>>>>>>> cyril.auburtin at gmail.com> wrote: >>>>>>>> >>>>>>>>> Similarly to: >>>>>>>>> >>>>>>>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>>>>>>> >>>>>>>>> I think it could be interesting to let a field empty in function >>>>>>>>> arguments >>>>>>>>> >>>>>>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i )` >>>>>>>>> >>>>>>>>> `function test(a,,b) { }` >>>>>>>>> >>>>>>>>> (but that would alter the current parsing, that doesn't allow it) >>>>>>>>> >>>>>>>>> Currently I often use `_` as a way to mark ignored fields, but >>>>>>>>> when there are more than 1 you need another identifier. A standard way >>>>>>>>> would be interesting rather >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> es-discuss mailing list >>>>>>>>> es-discuss at mozilla.org >>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> es-discuss mailing list >>>>>>>> es-discuss at mozilla.org >>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160811/85b15150/attachment-0001.html>
On Thu, Aug 11, 2016 at 1:28 PM, Isiah Meadows <isiahmeadows at gmail.com>
wrote:
If you're talking about ignored function parameters in a declaration or expression, much like
_
in several functional languages (like Haskell and Scala), I could see value in that. I'd prefer an explicit token for that, though, something like this:
'undefined' is what, too many characters to type?
( ( ignore_me, ignore_me2, asdf ) => { /* ... */ } ) (undefined, undefined, {whatever:1} )
// ImmutableJS: convert map to list, only
On Thu, Aug 11, 2016 at 1:28 PM, Isiah Meadows <isiahmeadows at gmail.com> wrote: > If you're talking about ignored function parameters in a declaration or > expression, much like `_` in several functional languages (like Haskell and > Scala), I could see value in that. I'd prefer an explicit token for that, > though, something like this: > 'undefined' is what, too many characters to type? ( ( ignore_me, ignore_me2, asdf ) => { /* ... */ } ) (undefined, undefined, {whatever:1} ) > ```js > // ImmutableJS: convert map to list, only > // keeping values with integer keys > map > .filter((*, key) => typeof key === "number" && key % 1 === 0) > .toList() > ``` > > On Thu, Aug 11, 2016, 12:51 Kris Siegel <krissiegel at gmail.com> wrote: > >> ignoring/skipping argument in functions declarations (indeed the >>> invocations could be let apart) >> >> >> I am of the opinion that this is not a problem that needs to be solved at >> the language standardization level. The commas (or really any separator) >> for "skipping" a parameter looks like a mistake and is unintuitive (it's >> certainly not obvious to me what its intent is had I seen it without the >> context of this thread). >> >> This seems like a problem solved with better coding practices. I >> typically make required parameters first and then any optional ones in a >> separate, single parameter called options. Callbacks can be done with >> chaining / promises / I fmake them required / etc. Skipping callbacks >> usually isn't a good idea. We could talk all day about who's coding >> practice is better than who's but ultimately this problem should be solved >> by developing / adopting good coding practices. >> >> (Honestly I'm not a fan of the skipping in arrays either but considering >> it's an array I feel like it's at least a magnitude less confusing than >> doing it with function parameters) >> >> On Thu, Aug 11, 2016 at 4:00 AM, Cyril Auburtin <cyril.auburtin at gmail.com >> > wrote: >> >>> > Confused by this thread. >>> >>> It's quite simple though, _ would be a useless allocated variable, you >>> an't have more than 1, ... >>> >>> > What is the problem that this proposal is trying to solve? >>> >>> ignoring/skipping argument in functions declarations (indeed the >>> invocations could be let apart) >>> >>> > `Math.min(x,,y)` >>> >>> yes this kind of thing would give NaN, that's why you can `Math.min(x, >>> , y)` write it with more spaces to avoid a typo mistake, indeed you could >>> still have like `Math.min(x, /*y (no longer used)*/ , z)` would. Like >>> said above, I realize the function invocations are sensible. >>> >>> So, it would be only for function declarations >>> >>> `div.addEventListener('click', () => { } )` says to skip all arguments, >>> and you've your callback scope is free of any additional vars >>> >>> `arr.forEach( x => { } )` says to only consider first argument, others >>> are skipped, and not in scope >>> >>> `Array.from({length: 19}, (, i) => i )` would be similar for the second >>> argument, similarly to array destructuring. It's not just for saving one >>> character, that's really not the matter, it's for standardizing this way, >>> because some people use `_`, some don't, .... >>> >>> 2016-08-10 16:27 GMT+02:00 Bob Myers <rtm at gol.com>: >>> >>>> Confused by this thread. >>>> >>>> > What if you could use a `.` as a wildcard? >>>> >>>> You can already use `_` or anything you want, as was already pointed >>>> out in early iterations of this idea. >>>> >>>> > it would avoid binding a usable identifier. >>>> >>>> What is the problem with that? >>>> >>>> What is the problem that this proposal is trying to solve? Any chance >>>> we could move on? >>>> >>>> Bob >>>> >>>> >>>> >>>> On Wed, Aug 10, 2016 at 7:48 PM, Alan Johnson <alan at breakrs.com> wrote: >>>> >>>>> What if you could use a `.` as a wildcard? I don’t think it would >>>>> conflict with existing syntax, and it would avoid binding a usable >>>>> identifier. It would be more obvious than nothing between the commas. >>>>> >>>>> >>>>> On Aug 8, 2016, at 06:33, Cyril Auburtin <cyril.auburtin at gmail.com> >>>>> wrote: >>>>> >>>>> Just bumping this up >>>>> >>>>> Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 >>>>> others undefined, this behavior is already a bit magic and similar to the >>>>> behavior of an array, so I still think foo(a,,b,,,c) should be like >>>>> foo(...[a,,b,,,c]) >>>>> >>>>> Other example: >>>>> ``` >>>>> var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => >>>>> undefined, 3 => 7} // here commas fantasies are allowed in arrays >>>>> m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // >>>>> setting implicitely value as undefined >>>>> m.set(3, ) // not allowed, which should be m.set(...[3,]) >>>>> ``` >>>>> >>>>> and again, it would help for callbacks too, `something( ( , , >>>>> thirdArg) => {} )` >>>>> >>>>> I saw this https://jeffmo.github.io/es-trailing-function-commas/, it >>>>> seems like a sub-case >>>>> >>>>> 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >>>>> >>>>>> One more similarity is that both function parameters and >>>>>> destructuring allow default values: (foo = 1) vs [foo = 1]. >>>>>> >>>>>> >>>>>> >>>>>> On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin < >>>>>> cyril.auburtin at gmail.com> wrote: >>>>>> >>>>>>> Since functions arguments is an array under the hood, they could >>>>>>> 'more behave the same' >>>>>>> >>>>>>> Both function arguments and arrays accept spreading: *[1, 2, >>>>>>> ...args] * and *fn(1, 2, ...args)* >>>>>>> >>>>>>> a function definition like *(,i) => {}*, would be the equivalent of *var >>>>>>> [,i] = arguments* >>>>>>> >>>>>>> an invocation *fn(,,i)* would be the equivalent of *[,,i]* >>>>>>> >>>>>>> It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, >>>>>>> but slightly less simply >>>>>>> >>>>>>> Are there possible issues with that 'extension' of function syntax? >>>>>>> >>>>>>> >>>>>>> 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >>>>>>> >>>>>>>> You could stop with "rare"; having to make up unused names is an >>>>>>>> obvious smell in comparison. >>>>>>>> >>>>>>>> ```js >>>>>>>> foo(UNUSED1, UNUSED2, x) >>>>>>>> >>>>>>>> foo(_, __, x) >>>>>>>> >>>>>>>> foo(,, x) >>>>>>>> >>>>>>>> foo(...[,, x]) >>>>>>>> ``` >>>>>>>> >>>>>>>> The latter is shorter and more explicit and would not be any more >>>>>>>> confusing if it became common. >>>>>>>> >>>>>>>> >>>>>>>> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >>>>>>>> >>>>>>>>> Eliding array elements is not "similar" to eliding function formal >>>>>>>>> parameters. The latter is extremely rare, hardly readable, confusing, >>>>>>>>> bug-prone, and unnecessary because there is already a "standard way" which >>>>>>>>> is to use any old parameter name you want: >>>>>>>>> >>>>>>>>> ```js >>>>>>>>> function foo(UNUSED1, UNUSED2, x) >>>>>>>>> ```` >>>>>>>>> >>>>>>>>> Most linters will not complain, or there are ways to shut them up >>>>>>>>> if they do. >>>>>>>>> >>>>>>>>> If you want to throw away an argument, just throw it away. >>>>>>>>> >>>>>>>>> ```js >>>>>>>>> function skipFirstParam(fn) { return ((first, ...args) => >>>>>>>>> fn(...args)); } >>>>>>>>> >>>>>>>>> `[1,2,3,4].map(skipFirstParam(i => i)); >>>>>>>>> >>>>>>>>> ``` >>>>>>>>> >>>>>>>>> Or use Renki's solution. >>>>>>>>> >>>>>>>>> Bob >>>>>>>>> >>>>>>>>> >>>>>>>>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>>>>>>>> cyril.auburtin at gmail.com> wrote: >>>>>>>>> >>>>>>>>>> Similarly to: >>>>>>>>>> >>>>>>>>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>>>>>>>> >>>>>>>>>> I think it could be interesting to let a field empty in function >>>>>>>>>> arguments >>>>>>>>>> >>>>>>>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i >>>>>>>>>> )` >>>>>>>>>> >>>>>>>>>> `function test(a,,b) { }` >>>>>>>>>> >>>>>>>>>> (but that would alter the current parsing, that doesn't allow it) >>>>>>>>>> >>>>>>>>>> Currently I often use `_` as a way to mark ignored fields, but >>>>>>>>>> when there are more than 1 you need another identifier. A standard way >>>>>>>>>> would be interesting rather >>>>>>>>>> >>>>>>>>>> _______________________________________________ >>>>>>>>>> es-discuss mailing list >>>>>>>>>> es-discuss at mozilla.org >>>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> es-discuss mailing list >>>>>>>>> es-discuss at mozilla.org >>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160811/48a58c6a/attachment-0001.html>
If you want to have new syntax for this feature, keyword void can be easily reused:
((void, void, void, param)=>param)(1,2,3,4) // 4
But I don't think it's worth it.
If you want to have new syntax for this feature, keyword void can be easily reused: ((void, void, void, param)=>param)(1,2,3,4) // 4 But I don't think it's worth it. On Thu, Aug 11, 2016 at 10:53 PM, J Decker <d3ck0r at gmail.com> wrote: > > > On Thu, Aug 11, 2016 at 1:28 PM, Isiah Meadows <isiahmeadows at gmail.com> > wrote: > >> If you're talking about ignored function parameters in a declaration or >> expression, much like `_` in several functional languages (like Haskell and >> Scala), I could see value in that. I'd prefer an explicit token for that, >> though, something like this: >> > > 'undefined' is what, too many characters to type? > > ( ( ignore_me, ignore_me2, asdf ) => { /* ... */ } ) (undefined, > undefined, {whatever:1} ) > > > > >> ```js >> > // ImmutableJS: convert map to list, only >> // keeping values with integer keys >> map >> .filter((*, key) => typeof key === "number" && key % 1 === 0) >> .toList() >> ``` >> >> On Thu, Aug 11, 2016, 12:51 Kris Siegel <krissiegel at gmail.com> wrote: >> >>> ignoring/skipping argument in functions declarations (indeed the >>>> invocations could be let apart) >>> >>> >>> I am of the opinion that this is not a problem that needs to be solved >>> at the language standardization level. The commas (or really any separator) >>> for "skipping" a parameter looks like a mistake and is unintuitive (it's >>> certainly not obvious to me what its intent is had I seen it without the >>> context of this thread). >>> >>> This seems like a problem solved with better coding practices. I >>> typically make required parameters first and then any optional ones in a >>> separate, single parameter called options. Callbacks can be done with >>> chaining / promises / I fmake them required / etc. Skipping callbacks >>> usually isn't a good idea. We could talk all day about who's coding >>> practice is better than who's but ultimately this problem should be solved >>> by developing / adopting good coding practices. >>> >>> (Honestly I'm not a fan of the skipping in arrays either but considering >>> it's an array I feel like it's at least a magnitude less confusing than >>> doing it with function parameters) >>> >>> On Thu, Aug 11, 2016 at 4:00 AM, Cyril Auburtin < >>> cyril.auburtin at gmail.com> wrote: >>> >>>> > Confused by this thread. >>>> >>>> It's quite simple though, _ would be a useless allocated variable, you >>>> an't have more than 1, ... >>>> >>>> > What is the problem that this proposal is trying to solve? >>>> >>>> ignoring/skipping argument in functions declarations (indeed the >>>> invocations could be let apart) >>>> >>>> > `Math.min(x,,y)` >>>> >>>> yes this kind of thing would give NaN, that's why you can `Math.min(x, >>>> , y)` write it with more spaces to avoid a typo mistake, indeed you could >>>> still have like `Math.min(x, /*y (no longer used)*/ , z)` would. Like >>>> said above, I realize the function invocations are sensible. >>>> >>>> So, it would be only for function declarations >>>> >>>> `div.addEventListener('click', () => { } )` says to skip all arguments, >>>> and you've your callback scope is free of any additional vars >>>> >>>> `arr.forEach( x => { } )` says to only consider first argument, others >>>> are skipped, and not in scope >>>> >>>> `Array.from({length: 19}, (, i) => i )` would be similar for the second >>>> argument, similarly to array destructuring. It's not just for saving one >>>> character, that's really not the matter, it's for standardizing this way, >>>> because some people use `_`, some don't, .... >>>> >>>> 2016-08-10 16:27 GMT+02:00 Bob Myers <rtm at gol.com>: >>>> >>>>> Confused by this thread. >>>>> >>>>> > What if you could use a `.` as a wildcard? >>>>> >>>>> You can already use `_` or anything you want, as was already pointed >>>>> out in early iterations of this idea. >>>>> >>>>> > it would avoid binding a usable identifier. >>>>> >>>>> What is the problem with that? >>>>> >>>>> What is the problem that this proposal is trying to solve? Any chance >>>>> we could move on? >>>>> >>>>> Bob >>>>> >>>>> >>>>> >>>>> On Wed, Aug 10, 2016 at 7:48 PM, Alan Johnson <alan at breakrs.com> >>>>> wrote: >>>>> >>>>>> What if you could use a `.` as a wildcard? I don’t think it would >>>>>> conflict with existing syntax, and it would avoid binding a usable >>>>>> identifier. It would be more obvious than nothing between the commas. >>>>>> >>>>>> >>>>>> On Aug 8, 2016, at 06:33, Cyril Auburtin <cyril.auburtin at gmail.com> >>>>>> wrote: >>>>>> >>>>>> Just bumping this up >>>>>> >>>>>> Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 >>>>>> others undefined, this behavior is already a bit magic and similar to the >>>>>> behavior of an array, so I still think foo(a,,b,,,c) should be like >>>>>> foo(...[a,,b,,,c]) >>>>>> >>>>>> Other example: >>>>>> ``` >>>>>> var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => >>>>>> undefined, 3 => 7} // here commas fantasies are allowed in arrays >>>>>> m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // >>>>>> setting implicitely value as undefined >>>>>> m.set(3, ) // not allowed, which should be m.set(...[3,]) >>>>>> ``` >>>>>> >>>>>> and again, it would help for callbacks too, `something( ( , , >>>>>> thirdArg) => {} )` >>>>>> >>>>>> I saw this https://jeffmo.github.io/es-trailing-function-commas/, it >>>>>> seems like a sub-case >>>>>> >>>>>> 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >>>>>> >>>>>>> One more similarity is that both function parameters and >>>>>>> destructuring allow default values: (foo = 1) vs [foo = 1]. >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin < >>>>>>> cyril.auburtin at gmail.com> wrote: >>>>>>> >>>>>>>> Since functions arguments is an array under the hood, they could >>>>>>>> 'more behave the same' >>>>>>>> >>>>>>>> Both function arguments and arrays accept spreading: *[1, 2, >>>>>>>> ...args] * and *fn(1, 2, ...args)* >>>>>>>> >>>>>>>> a function definition like *(,i) => {}*, would be the equivalent of >>>>>>>> *var [,i] = arguments* >>>>>>>> >>>>>>>> an invocation *fn(,,i)* would be the equivalent of *[,,i]* >>>>>>>> >>>>>>>> It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, >>>>>>>> but slightly less simply >>>>>>>> >>>>>>>> Are there possible issues with that 'extension' of function syntax? >>>>>>>> >>>>>>>> >>>>>>>> 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com> >>>>>>>> : >>>>>>>> >>>>>>>>> You could stop with "rare"; having to make up unused names is an >>>>>>>>> obvious smell in comparison. >>>>>>>>> >>>>>>>>> ```js >>>>>>>>> foo(UNUSED1, UNUSED2, x) >>>>>>>>> >>>>>>>>> foo(_, __, x) >>>>>>>>> >>>>>>>>> foo(,, x) >>>>>>>>> >>>>>>>>> foo(...[,, x]) >>>>>>>>> ``` >>>>>>>>> >>>>>>>>> The latter is shorter and more explicit and would not be any more >>>>>>>>> confusing if it became common. >>>>>>>>> >>>>>>>>> >>>>>>>>> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >>>>>>>>> >>>>>>>>>> Eliding array elements is not "similar" to eliding function >>>>>>>>>> formal parameters. The latter is extremely rare, hardly readable, >>>>>>>>>> confusing, bug-prone, and unnecessary because there is already a "standard >>>>>>>>>> way" which is to use any old parameter name you want: >>>>>>>>>> >>>>>>>>>> ```js >>>>>>>>>> function foo(UNUSED1, UNUSED2, x) >>>>>>>>>> ```` >>>>>>>>>> >>>>>>>>>> Most linters will not complain, or there are ways to shut them up >>>>>>>>>> if they do. >>>>>>>>>> >>>>>>>>>> If you want to throw away an argument, just throw it away. >>>>>>>>>> >>>>>>>>>> ```js >>>>>>>>>> function skipFirstParam(fn) { return ((first, ...args) => >>>>>>>>>> fn(...args)); } >>>>>>>>>> >>>>>>>>>> `[1,2,3,4].map(skipFirstParam(i => i)); >>>>>>>>>> >>>>>>>>>> ``` >>>>>>>>>> >>>>>>>>>> Or use Renki's solution. >>>>>>>>>> >>>>>>>>>> Bob >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>>>>>>>>> cyril.auburtin at gmail.com> wrote: >>>>>>>>>> >>>>>>>>>>> Similarly to: >>>>>>>>>>> >>>>>>>>>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>>>>>>>>> >>>>>>>>>>> I think it could be interesting to let a field empty in function >>>>>>>>>>> arguments >>>>>>>>>>> >>>>>>>>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => i >>>>>>>>>>> )` >>>>>>>>>>> >>>>>>>>>>> `function test(a,,b) { }` >>>>>>>>>>> >>>>>>>>>>> (but that would alter the current parsing, that doesn't allow it) >>>>>>>>>>> >>>>>>>>>>> Currently I often use `_` as a way to mark ignored fields, but >>>>>>>>>>> when there are more than 1 you need another identifier. A standard way >>>>>>>>>>> would be interesting rather >>>>>>>>>>> >>>>>>>>>>> _______________________________________________ >>>>>>>>>>> es-discuss mailing list >>>>>>>>>>> es-discuss at mozilla.org >>>>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> _______________________________________________ >>>>>>>>>> es-discuss mailing list >>>>>>>>>> es-discuss at mozilla.org >>>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>>> >>>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160811/3cb286d9/attachment-0001.html>
( ( ignore_me, ignore_me2, asdf ) => { /* ... */ } ) (undefined, undefined, {whatever:1} )
Let's forget about functions invocations, a bad idea, so that's more
the ignore_me, ignore_me2
that are quite polluting/unpractical
I'm not either a fan of skipping in arrays, but again function arguments is an array, that same syntax would represent literally holes. There's also like for invocations the risks of a typo, but the coder has to be really distracted to not see it..
Thanks for that discussion, it'll very likely never make it to the spec, and sorry my last message had typos, corrected on esdiscuss.org topic/ignoring-arguments, mailing-lists :/
> `( ( ignore_me, ignore_me2, asdf ) => { /* ... */ } ) (undefined, undefined, {whatever:1} )` Let's forget about functions invocations, a bad idea, so that's more the `ignore_me, ignore_me2` that are quite polluting/unpractical I'm not either a fan of skipping in arrays, but again function arguments is an array, that same syntax represent literally holes. there's also like for invocations the risks of a typo, but the coder has to be really distracted to not see it.. Thanks for that discussion, it'll very likely never make it to the spec, and sorry my last message had typos, corrected on https://esdiscuss.org/ topic/ignoring-arguments, mailing-lists :/ 2016-08-11 23:44 GMT+02:00 Michał Wadas <michalwadas at gmail.com>: > If you want to have new syntax for this feature, keyword void can be > easily reused: > > ((void, void, void, param)=>param)(1,2,3,4) // 4 > > But I don't think it's worth it. > > On Thu, Aug 11, 2016 at 10:53 PM, J Decker <d3ck0r at gmail.com> wrote: > >> >> >> On Thu, Aug 11, 2016 at 1:28 PM, Isiah Meadows <isiahmeadows at gmail.com> >> wrote: >> >>> If you're talking about ignored function parameters in a declaration or >>> expression, much like `_` in several functional languages (like Haskell and >>> Scala), I could see value in that. I'd prefer an explicit token for that, >>> though, something like this: >>> >> >> 'undefined' is what, too many characters to type? >> >> ( ( ignore_me, ignore_me2, asdf ) => { /* ... */ } ) (undefined, >> undefined, {whatever:1} ) >> >> >> >> >>> ```js >>> >> // ImmutableJS: convert map to list, only >>> // keeping values with integer keys >>> map >>> .filter((*, key) => typeof key === "number" && key % 1 === 0) >>> .toList() >>> ``` >>> >>> On Thu, Aug 11, 2016, 12:51 Kris Siegel <krissiegel at gmail.com> wrote: >>> >>>> ignoring/skipping argument in functions declarations (indeed the >>>>> invocations could be let apart) >>>> >>>> >>>> I am of the opinion that this is not a problem that needs to be solved >>>> at the language standardization level. The commas (or really any separator) >>>> for "skipping" a parameter looks like a mistake and is unintuitive (it's >>>> certainly not obvious to me what its intent is had I seen it without the >>>> context of this thread). >>>> >>>> This seems like a problem solved with better coding practices. I >>>> typically make required parameters first and then any optional ones in a >>>> separate, single parameter called options. Callbacks can be done with >>>> chaining / promises / I fmake them required / etc. Skipping callbacks >>>> usually isn't a good idea. We could talk all day about who's coding >>>> practice is better than who's but ultimately this problem should be solved >>>> by developing / adopting good coding practices. >>>> >>>> (Honestly I'm not a fan of the skipping in arrays either but >>>> considering it's an array I feel like it's at least a magnitude less >>>> confusing than doing it with function parameters) >>>> >>>> On Thu, Aug 11, 2016 at 4:00 AM, Cyril Auburtin < >>>> cyril.auburtin at gmail.com> wrote: >>>> >>>>> > Confused by this thread. >>>>> >>>>> It's quite simple though, _ would be a useless allocated variable, you >>>>> an't have more than 1, ... >>>>> >>>>> > What is the problem that this proposal is trying to solve? >>>>> >>>>> ignoring/skipping argument in functions declarations (indeed the >>>>> invocations could be let apart) >>>>> >>>>> > `Math.min(x,,y)` >>>>> >>>>> yes this kind of thing would give NaN, that's why you can `Math.min(x, >>>>> , y)` write it with more spaces to avoid a typo mistake, indeed you could >>>>> still have like `Math.min(x, /*y (no longer used)*/ , z)` would. Like >>>>> said above, I realize the function invocations are sensible. >>>>> >>>>> So, it would be only for function declarations >>>>> >>>>> `div.addEventListener('click', () => { } )` says to skip all >>>>> arguments, and you've your callback scope is free of any additional vars >>>>> >>>>> `arr.forEach( x => { } )` says to only consider first argument, others >>>>> are skipped, and not in scope >>>>> >>>>> `Array.from({length: 19}, (, i) => i )` would be similar for the >>>>> second argument, similarly to array destructuring. It's not just for saving >>>>> one character, that's really not the matter, it's for standardizing this >>>>> way, because some people use `_`, some don't, .... >>>>> >>>>> 2016-08-10 16:27 GMT+02:00 Bob Myers <rtm at gol.com>: >>>>> >>>>>> Confused by this thread. >>>>>> >>>>>> > What if you could use a `.` as a wildcard? >>>>>> >>>>>> You can already use `_` or anything you want, as was already pointed >>>>>> out in early iterations of this idea. >>>>>> >>>>>> > it would avoid binding a usable identifier. >>>>>> >>>>>> What is the problem with that? >>>>>> >>>>>> What is the problem that this proposal is trying to solve? Any chance >>>>>> we could move on? >>>>>> >>>>>> Bob >>>>>> >>>>>> >>>>>> >>>>>> On Wed, Aug 10, 2016 at 7:48 PM, Alan Johnson <alan at breakrs.com> >>>>>> wrote: >>>>>> >>>>>>> What if you could use a `.` as a wildcard? I don’t think it would >>>>>>> conflict with existing syntax, and it would avoid binding a usable >>>>>>> identifier. It would be more obvious than nothing between the commas. >>>>>>> >>>>>>> >>>>>>> On Aug 8, 2016, at 06:33, Cyril Auburtin <cyril.auburtin at gmail.com> >>>>>>> wrote: >>>>>>> >>>>>>> Just bumping this up >>>>>>> >>>>>>> Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 >>>>>>> others undefined, this behavior is already a bit magic and similar to the >>>>>>> behavior of an array, so I still think foo(a,,b,,,c) should be like >>>>>>> foo(...[a,,b,,,c]) >>>>>>> >>>>>>> Other example: >>>>>>> ``` >>>>>>> var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => >>>>>>> undefined, 3 => 7} // here commas fantasies are allowed in arrays >>>>>>> m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // >>>>>>> setting implicitely value as undefined >>>>>>> m.set(3, ) // not allowed, which should be m.set(...[3,]) >>>>>>> ``` >>>>>>> >>>>>>> and again, it would help for callbacks too, `something( ( , , >>>>>>> thirdArg) => {} )` >>>>>>> >>>>>>> I saw this https://jeffmo.github.io/es-trailing-function-commas/, >>>>>>> it seems like a sub-case >>>>>>> >>>>>>> 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com>: >>>>>>> >>>>>>>> One more similarity is that both function parameters and >>>>>>>> destructuring allow default values: (foo = 1) vs [foo = 1]. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin < >>>>>>>> cyril.auburtin at gmail.com> wrote: >>>>>>>> >>>>>>>>> Since functions arguments is an array under the hood, they could >>>>>>>>> 'more behave the same' >>>>>>>>> >>>>>>>>> Both function arguments and arrays accept spreading: *[1, 2, >>>>>>>>> ...args] * and *fn(1, 2, ...args)* >>>>>>>>> >>>>>>>>> a function definition like *(,i) => {}*, would be the equivalent >>>>>>>>> of *var [,i] = arguments* >>>>>>>>> >>>>>>>>> an invocation *fn(,,i)* would be the equivalent of *[,,i]* >>>>>>>>> >>>>>>>>> It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, >>>>>>>>> but slightly less simply >>>>>>>>> >>>>>>>>> Are there possible issues with that 'extension' of function syntax? >>>>>>>>> >>>>>>>>> >>>>>>>>> 2016-05-29 21:32 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com >>>>>>>>> >: >>>>>>>>> >>>>>>>>>> You could stop with "rare"; having to make up unused names is an >>>>>>>>>> obvious smell in comparison. >>>>>>>>>> >>>>>>>>>> ```js >>>>>>>>>> foo(UNUSED1, UNUSED2, x) >>>>>>>>>> >>>>>>>>>> foo(_, __, x) >>>>>>>>>> >>>>>>>>>> foo(,, x) >>>>>>>>>> >>>>>>>>>> foo(...[,, x]) >>>>>>>>>> ``` >>>>>>>>>> >>>>>>>>>> The latter is shorter and more explicit and would not be any more >>>>>>>>>> confusing if it became common. >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >>>>>>>>>> >>>>>>>>>>> Eliding array elements is not "similar" to eliding function >>>>>>>>>>> formal parameters. The latter is extremely rare, hardly readable, >>>>>>>>>>> confusing, bug-prone, and unnecessary because there is already a "standard >>>>>>>>>>> way" which is to use any old parameter name you want: >>>>>>>>>>> >>>>>>>>>>> ```js >>>>>>>>>>> function foo(UNUSED1, UNUSED2, x) >>>>>>>>>>> ```` >>>>>>>>>>> >>>>>>>>>>> Most linters will not complain, or there are ways to shut them >>>>>>>>>>> up if they do. >>>>>>>>>>> >>>>>>>>>>> If you want to throw away an argument, just throw it away. >>>>>>>>>>> >>>>>>>>>>> ```js >>>>>>>>>>> function skipFirstParam(fn) { return ((first, ...args) => >>>>>>>>>>> fn(...args)); } >>>>>>>>>>> >>>>>>>>>>> `[1,2,3,4].map(skipFirstParam(i => i)); >>>>>>>>>>> >>>>>>>>>>> ``` >>>>>>>>>>> >>>>>>>>>>> Or use Renki's solution. >>>>>>>>>>> >>>>>>>>>>> Bob >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>>>>>>>>>> cyril.auburtin at gmail.com> wrote: >>>>>>>>>>> >>>>>>>>>>>> Similarly to: >>>>>>>>>>>> >>>>>>>>>>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>>>>>>>>>> >>>>>>>>>>>> I think it could be interesting to let a field empty in >>>>>>>>>>>> function arguments >>>>>>>>>>>> >>>>>>>>>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => >>>>>>>>>>>> i )` >>>>>>>>>>>> >>>>>>>>>>>> `function test(a,,b) { }` >>>>>>>>>>>> >>>>>>>>>>>> (but that would alter the current parsing, that doesn't allow >>>>>>>>>>>> it) >>>>>>>>>>>> >>>>>>>>>>>> Currently I often use `_` as a way to mark ignored fields, but >>>>>>>>>>>> when there are more than 1 you need another identifier. A standard way >>>>>>>>>>>> would be interesting rather >>>>>>>>>>>> >>>>>>>>>>>> _______________________________________________ >>>>>>>>>>>> es-discuss mailing list >>>>>>>>>>>> es-discuss at mozilla.org >>>>>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> _______________________________________________ >>>>>>>>>>> es-discuss mailing list >>>>>>>>>>> es-discuss at mozilla.org >>>>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> _______________________________________________ >>>>>>> es-discuss mailing list >>>>>>> es-discuss at mozilla.org >>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>> >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> es-discuss mailing list >>>>>>> es-discuss at mozilla.org >>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>> >>>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160812/570b02b0/attachment-0001.html>
On Thu, Aug 11, 2016 at 5:55 PM, Cyril Auburtin <cyril.auburtin at gmail.com>
wrote:
( ( ignore_me, ignore_me2, asdf ) => { /* ... */ } ) (undefined, undefined, {whatever:1} )
Let's forget about functions invocations, a bad idea, so that's more the
ignore_me, ignore_me2
that are quite polluting/unpracticalI'm not either a fan of skipping in arrays, but again function arguments is an array, that same syntax represent literally holes. there's also like for invocations the risks of a typo, but the coder has to be really distracted to not see it..
Thanks for that discussion, it'll very likely never make it to the spec, and sorry my last message had typos, corrected on esdiscuss.org/topic/ignoring-arguments, mailing-lists :/
but the point of that really is... why can't you just use the token 'undefined' instead of trying to use whitespace?
On Thu, Aug 11, 2016 at 5:55 PM, Cyril Auburtin <cyril.auburtin at gmail.com> wrote: > > `( ( ignore_me, ignore_me2, asdf ) => { /* ... */ } ) (undefined, > undefined, {whatever:1} )` > > Let's forget about functions invocations, a bad idea, so that's more the `ignore_me, > ignore_me2` that are quite polluting/unpractical > > I'm not either a fan of skipping in arrays, but again function arguments > is an array, that same syntax represent literally holes. there's also > like for invocations the risks of a typo, but the coder has to be really > distracted to not see it.. > > Thanks for that discussion, it'll very likely never make it to the spec, > and sorry my last message had typos, corrected on > https://esdiscuss.org/topic/ignoring-arguments, mailing-lists :/ > > but the point of that really is... why can't you just use the token 'undefined' instead of trying to use whitespace? > 2016-08-11 23:44 GMT+02:00 Michał Wadas <michalwadas at gmail.com>: > >> If you want to have new syntax for this feature, keyword void can be >> easily reused: >> >> ((void, void, void, param)=>param)(1,2,3,4) // 4 >> >> But I don't think it's worth it. >> >> On Thu, Aug 11, 2016 at 10:53 PM, J Decker <d3ck0r at gmail.com> wrote: >> >>> >>> >>> On Thu, Aug 11, 2016 at 1:28 PM, Isiah Meadows <isiahmeadows at gmail.com> >>> wrote: >>> >>>> If you're talking about ignored function parameters in a declaration or >>>> expression, much like `_` in several functional languages (like Haskell and >>>> Scala), I could see value in that. I'd prefer an explicit token for that, >>>> though, something like this: >>>> >>> >>> 'undefined' is what, too many characters to type? >>> >>> ( ( ignore_me, ignore_me2, asdf ) => { /* ... */ } ) (undefined, >>> undefined, {whatever:1} ) >>> >>> >>> >>> >>>> ```js >>>> >>> // ImmutableJS: convert map to list, only >>>> // keeping values with integer keys >>>> map >>>> .filter((*, key) => typeof key === "number" && key % 1 === 0) >>>> .toList() >>>> ``` >>>> >>>> On Thu, Aug 11, 2016, 12:51 Kris Siegel <krissiegel at gmail.com> wrote: >>>> >>>>> ignoring/skipping argument in functions declarations (indeed the >>>>>> invocations could be let apart) >>>>> >>>>> >>>>> I am of the opinion that this is not a problem that needs to be solved >>>>> at the language standardization level. The commas (or really any separator) >>>>> for "skipping" a parameter looks like a mistake and is unintuitive (it's >>>>> certainly not obvious to me what its intent is had I seen it without the >>>>> context of this thread). >>>>> >>>>> This seems like a problem solved with better coding practices. I >>>>> typically make required parameters first and then any optional ones in a >>>>> separate, single parameter called options. Callbacks can be done with >>>>> chaining / promises / I fmake them required / etc. Skipping callbacks >>>>> usually isn't a good idea. We could talk all day about who's coding >>>>> practice is better than who's but ultimately this problem should be solved >>>>> by developing / adopting good coding practices. >>>>> >>>>> (Honestly I'm not a fan of the skipping in arrays either but >>>>> considering it's an array I feel like it's at least a magnitude less >>>>> confusing than doing it with function parameters) >>>>> >>>>> On Thu, Aug 11, 2016 at 4:00 AM, Cyril Auburtin < >>>>> cyril.auburtin at gmail.com> wrote: >>>>> >>>>>> > Confused by this thread. >>>>>> >>>>>> It's quite simple though, _ would be a useless allocated variable, >>>>>> you an't have more than 1, ... >>>>>> >>>>>> > What is the problem that this proposal is trying to solve? >>>>>> >>>>>> ignoring/skipping argument in functions declarations (indeed the >>>>>> invocations could be let apart) >>>>>> >>>>>> > `Math.min(x,,y)` >>>>>> >>>>>> yes this kind of thing would give NaN, that's why you can `Math.min(x, >>>>>> , y)` write it with more spaces to avoid a typo mistake, indeed you could >>>>>> still have like `Math.min(x, /*y (no longer used)*/ , z)` would. >>>>>> Like said above, I realize the function invocations are sensible. >>>>>> >>>>>> So, it would be only for function declarations >>>>>> >>>>>> `div.addEventListener('click', () => { } )` says to skip all >>>>>> arguments, and you've your callback scope is free of any additional vars >>>>>> >>>>>> `arr.forEach( x => { } )` says to only consider first argument, >>>>>> others are skipped, and not in scope >>>>>> >>>>>> `Array.from({length: 19}, (, i) => i )` would be similar for the >>>>>> second argument, similarly to array destructuring. It's not just for saving >>>>>> one character, that's really not the matter, it's for standardizing this >>>>>> way, because some people use `_`, some don't, .... >>>>>> >>>>>> 2016-08-10 16:27 GMT+02:00 Bob Myers <rtm at gol.com>: >>>>>> >>>>>>> Confused by this thread. >>>>>>> >>>>>>> > What if you could use a `.` as a wildcard? >>>>>>> >>>>>>> You can already use `_` or anything you want, as was already pointed >>>>>>> out in early iterations of this idea. >>>>>>> >>>>>>> > it would avoid binding a usable identifier. >>>>>>> >>>>>>> What is the problem with that? >>>>>>> >>>>>>> What is the problem that this proposal is trying to solve? Any >>>>>>> chance we could move on? >>>>>>> >>>>>>> Bob >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Wed, Aug 10, 2016 at 7:48 PM, Alan Johnson <alan at breakrs.com> >>>>>>> wrote: >>>>>>> >>>>>>>> What if you could use a `.` as a wildcard? I don’t think it would >>>>>>>> conflict with existing syntax, and it would avoid binding a usable >>>>>>>> identifier. It would be more obvious than nothing between the commas. >>>>>>>> >>>>>>>> >>>>>>>> On Aug 8, 2016, at 06:33, Cyril Auburtin <cyril.auburtin at gmail.com> >>>>>>>> wrote: >>>>>>>> >>>>>>>> Just bumping this up >>>>>>>> >>>>>>>> Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 >>>>>>>> others undefined, this behavior is already a bit magic and similar to the >>>>>>>> behavior of an array, so I still think foo(a,,b,,,c) should be like >>>>>>>> foo(...[a,,b,,,c]) >>>>>>>> >>>>>>>> Other example: >>>>>>>> ``` >>>>>>>> var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => >>>>>>>> undefined, 3 => 7} // here commas fantasies are allowed in arrays >>>>>>>> m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} // >>>>>>>> setting implicitely value as undefined >>>>>>>> m.set(3, ) // not allowed, which should be m.set(...[3,]) >>>>>>>> ``` >>>>>>>> >>>>>>>> and again, it would help for callbacks too, `something( ( , , >>>>>>>> thirdArg) => {} )` >>>>>>>> >>>>>>>> I saw this https://jeffmo.github.io/es-trailing-function-commas/, >>>>>>>> it seems like a sub-case >>>>>>>> >>>>>>>> 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com> >>>>>>>> : >>>>>>>> >>>>>>>>> One more similarity is that both function parameters and >>>>>>>>> destructuring allow default values: (foo = 1) vs [foo = 1]. >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin < >>>>>>>>> cyril.auburtin at gmail.com> wrote: >>>>>>>>> >>>>>>>>>> Since functions arguments is an array under the hood, they could >>>>>>>>>> 'more behave the same' >>>>>>>>>> >>>>>>>>>> Both function arguments and arrays accept spreading: *[1, 2, >>>>>>>>>> ...args] * and *fn(1, 2, ...args)* >>>>>>>>>> >>>>>>>>>> a function definition like *(,i) => {}*, would be the equivalent >>>>>>>>>> of *var [,i] = arguments* >>>>>>>>>> >>>>>>>>>> an invocation *fn(,,i)* would be the equivalent of *[,,i]* >>>>>>>>>> >>>>>>>>>> It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki said, >>>>>>>>>> but slightly less simply >>>>>>>>>> >>>>>>>>>> Are there possible issues with that 'extension' of function >>>>>>>>>> syntax? >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> 2016-05-29 21:32 GMT+02:00 Renki Ivanko < >>>>>>>>>> fatalis.erratum at gmail.com>: >>>>>>>>>> >>>>>>>>>>> You could stop with "rare"; having to make up unused names is an >>>>>>>>>>> obvious smell in comparison. >>>>>>>>>>> >>>>>>>>>>> ```js >>>>>>>>>>> foo(UNUSED1, UNUSED2, x) >>>>>>>>>>> >>>>>>>>>>> foo(_, __, x) >>>>>>>>>>> >>>>>>>>>>> foo(,, x) >>>>>>>>>>> >>>>>>>>>>> foo(...[,, x]) >>>>>>>>>>> ``` >>>>>>>>>>> >>>>>>>>>>> The latter is shorter and more explicit and would not be any >>>>>>>>>>> more confusing if it became common. >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >>>>>>>>>>> >>>>>>>>>>>> Eliding array elements is not "similar" to eliding function >>>>>>>>>>>> formal parameters. The latter is extremely rare, hardly readable, >>>>>>>>>>>> confusing, bug-prone, and unnecessary because there is already a "standard >>>>>>>>>>>> way" which is to use any old parameter name you want: >>>>>>>>>>>> >>>>>>>>>>>> ```js >>>>>>>>>>>> function foo(UNUSED1, UNUSED2, x) >>>>>>>>>>>> ```` >>>>>>>>>>>> >>>>>>>>>>>> Most linters will not complain, or there are ways to shut them >>>>>>>>>>>> up if they do. >>>>>>>>>>>> >>>>>>>>>>>> If you want to throw away an argument, just throw it away. >>>>>>>>>>>> >>>>>>>>>>>> ```js >>>>>>>>>>>> function skipFirstParam(fn) { return ((first, ...args) => >>>>>>>>>>>> fn(...args)); } >>>>>>>>>>>> >>>>>>>>>>>> `[1,2,3,4].map(skipFirstParam(i => i)); >>>>>>>>>>>> >>>>>>>>>>>> ``` >>>>>>>>>>>> >>>>>>>>>>>> Or use Renki's solution. >>>>>>>>>>>> >>>>>>>>>>>> Bob >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>>>>>>>>>>> cyril.auburtin at gmail.com> wrote: >>>>>>>>>>>> >>>>>>>>>>>>> Similarly to: >>>>>>>>>>>>> >>>>>>>>>>>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>>>>>>>>>>> >>>>>>>>>>>>> I think it could be interesting to let a field empty in >>>>>>>>>>>>> function arguments >>>>>>>>>>>>> >>>>>>>>>>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) => >>>>>>>>>>>>> i )` >>>>>>>>>>>>> >>>>>>>>>>>>> `function test(a,,b) { }` >>>>>>>>>>>>> >>>>>>>>>>>>> (but that would alter the current parsing, that doesn't allow >>>>>>>>>>>>> it) >>>>>>>>>>>>> >>>>>>>>>>>>> Currently I often use `_` as a way to mark ignored fields, but >>>>>>>>>>>>> when there are more than 1 you need another identifier. A standard way >>>>>>>>>>>>> would be interesting rather >>>>>>>>>>>>> >>>>>>>>>>>>> _______________________________________________ >>>>>>>>>>>>> es-discuss mailing list >>>>>>>>>>>>> es-discuss at mozilla.org >>>>>>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> _______________________________________________ >>>>>>>>>>>> es-discuss mailing list >>>>>>>>>>>> es-discuss at mozilla.org >>>>>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> es-discuss mailing list >>>>>>>> es-discuss at mozilla.org >>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> es-discuss mailing list >>>>>>>> es-discuss at mozilla.org >>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160811/54389519/attachment-0001.html>
If we are talking about function definitions, It doesn't do exactly what a hole is supposed to do
[1,2,3,4].map((undefined, i)=>i) // undefined act as a variable
[1,2,3,4].map((undefined, undefined, i)=>i) // so no
2016-08-12 4:04 GMT+02:00 J Decker <d3ck0r at gmail.com>:
If we are talking about function definitions, It doesn't do exactly what a hole is supposed to do ``` [1,2,3,4].map((undefined, i)=>i) // undefined act as a variable [1,2,3,4].map((undefined, undefined, i)=>i) // so no ``` 2016-08-12 4:04 GMT+02:00 J Decker <d3ck0r at gmail.com>: > > > On Thu, Aug 11, 2016 at 5:55 PM, Cyril Auburtin <cyril.auburtin at gmail.com> > wrote: > >> > `( ( ignore_me, ignore_me2, asdf ) => { /* ... */ } ) (undefined, >> undefined, {whatever:1} )` >> >> Let's forget about functions invocations, a bad idea, so that's more the `ignore_me, >> ignore_me2` that are quite polluting/unpractical >> >> I'm not either a fan of skipping in arrays, but again function arguments >> is an array, that same syntax represent literally holes. there's also >> like for invocations the risks of a typo, but the coder has to be really >> distracted to not see it.. >> >> Thanks for that discussion, it'll very likely never make it to the spec, >> and sorry my last message had typos, corrected on >> https://esdiscuss.org/topic/ignoring-arguments, mailing-lists :/ >> >> > but the point of that really is... why can't you just use the token > 'undefined' instead of trying to use whitespace? > > > >> 2016-08-11 23:44 GMT+02:00 Michał Wadas <michalwadas at gmail.com>: >> >>> If you want to have new syntax for this feature, keyword void can be >>> easily reused: >>> >>> ((void, void, void, param)=>param)(1,2,3,4) // 4 >>> >>> But I don't think it's worth it. >>> >>> On Thu, Aug 11, 2016 at 10:53 PM, J Decker <d3ck0r at gmail.com> wrote: >>> >>>> >>>> >>>> On Thu, Aug 11, 2016 at 1:28 PM, Isiah Meadows <isiahmeadows at gmail.com> >>>> wrote: >>>> >>>>> If you're talking about ignored function parameters in a declaration >>>>> or expression, much like `_` in several functional languages (like Haskell >>>>> and Scala), I could see value in that. I'd prefer an explicit token for >>>>> that, though, something like this: >>>>> >>>> >>>> 'undefined' is what, too many characters to type? >>>> >>>> ( ( ignore_me, ignore_me2, asdf ) => { /* ... */ } ) (undefined, >>>> undefined, {whatever:1} ) >>>> >>>> >>>> >>>> >>>>> ```js >>>>> >>>> // ImmutableJS: convert map to list, only >>>>> // keeping values with integer keys >>>>> map >>>>> .filter((*, key) => typeof key === "number" && key % 1 === 0) >>>>> .toList() >>>>> ``` >>>>> >>>>> On Thu, Aug 11, 2016, 12:51 Kris Siegel <krissiegel at gmail.com> wrote: >>>>> >>>>>> ignoring/skipping argument in functions declarations (indeed the >>>>>>> invocations could be let apart) >>>>>> >>>>>> >>>>>> I am of the opinion that this is not a problem that needs to be >>>>>> solved at the language standardization level. The commas (or really any >>>>>> separator) for "skipping" a parameter looks like a mistake and is >>>>>> unintuitive (it's certainly not obvious to me what its intent is had I seen >>>>>> it without the context of this thread). >>>>>> >>>>>> This seems like a problem solved with better coding practices. I >>>>>> typically make required parameters first and then any optional ones in a >>>>>> separate, single parameter called options. Callbacks can be done with >>>>>> chaining / promises / I fmake them required / etc. Skipping callbacks >>>>>> usually isn't a good idea. We could talk all day about who's coding >>>>>> practice is better than who's but ultimately this problem should be solved >>>>>> by developing / adopting good coding practices. >>>>>> >>>>>> (Honestly I'm not a fan of the skipping in arrays either but >>>>>> considering it's an array I feel like it's at least a magnitude less >>>>>> confusing than doing it with function parameters) >>>>>> >>>>>> On Thu, Aug 11, 2016 at 4:00 AM, Cyril Auburtin < >>>>>> cyril.auburtin at gmail.com> wrote: >>>>>> >>>>>>> > Confused by this thread. >>>>>>> >>>>>>> It's quite simple though, _ would be a useless allocated variable, >>>>>>> you an't have more than 1, ... >>>>>>> >>>>>>> > What is the problem that this proposal is trying to solve? >>>>>>> >>>>>>> ignoring/skipping argument in functions declarations (indeed the >>>>>>> invocations could be let apart) >>>>>>> >>>>>>> > `Math.min(x,,y)` >>>>>>> >>>>>>> yes this kind of thing would give NaN, that's why you can `Math.min(x, >>>>>>> , y)` write it with more spaces to avoid a typo mistake, indeed you could >>>>>>> still have like `Math.min(x, /*y (no longer used)*/ , z)` would. >>>>>>> Like said above, I realize the function invocations are sensible. >>>>>>> >>>>>>> So, it would be only for function declarations >>>>>>> >>>>>>> `div.addEventListener('click', () => { } )` says to skip all >>>>>>> arguments, and you've your callback scope is free of any additional vars >>>>>>> >>>>>>> `arr.forEach( x => { } )` says to only consider first argument, >>>>>>> others are skipped, and not in scope >>>>>>> >>>>>>> `Array.from({length: 19}, (, i) => i )` would be similar for the >>>>>>> second argument, similarly to array destructuring. It's not just for saving >>>>>>> one character, that's really not the matter, it's for standardizing this >>>>>>> way, because some people use `_`, some don't, .... >>>>>>> >>>>>>> 2016-08-10 16:27 GMT+02:00 Bob Myers <rtm at gol.com>: >>>>>>> >>>>>>>> Confused by this thread. >>>>>>>> >>>>>>>> > What if you could use a `.` as a wildcard? >>>>>>>> >>>>>>>> You can already use `_` or anything you want, as was already >>>>>>>> pointed out in early iterations of this idea. >>>>>>>> >>>>>>>> > it would avoid binding a usable identifier. >>>>>>>> >>>>>>>> What is the problem with that? >>>>>>>> >>>>>>>> What is the problem that this proposal is trying to solve? Any >>>>>>>> chance we could move on? >>>>>>>> >>>>>>>> Bob >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Wed, Aug 10, 2016 at 7:48 PM, Alan Johnson <alan at breakrs.com> >>>>>>>> wrote: >>>>>>>> >>>>>>>>> What if you could use a `.` as a wildcard? I don’t think it would >>>>>>>>> conflict with existing syntax, and it would avoid binding a usable >>>>>>>>> identifier. It would be more obvious than nothing between the commas. >>>>>>>>> >>>>>>>>> >>>>>>>>> On Aug 8, 2016, at 06:33, Cyril Auburtin <cyril.auburtin at gmail.com> >>>>>>>>> wrote: >>>>>>>>> >>>>>>>>> Just bumping this up >>>>>>>>> >>>>>>>>> Calling `foo(1)` where foo is defined with 3 arguments, lets the 2 >>>>>>>>> others undefined, this behavior is already a bit magic and similar to the >>>>>>>>> behavior of an array, so I still think foo(a,,b,,,c) should be like >>>>>>>>> foo(...[a,,b,,,c]) >>>>>>>>> >>>>>>>>> Other example: >>>>>>>>> ``` >>>>>>>>> var m=new Map([[1], [2,], [3,7]]) // Map {1 => undefined, 2 => >>>>>>>>> undefined, 3 => 7} // here commas fantasies are allowed in arrays >>>>>>>>> m.set(3) // Map {1 => undefined, 2 => undefined, 3 => undefined} >>>>>>>>> // setting implicitely value as undefined >>>>>>>>> m.set(3, ) // not allowed, which should be m.set(...[3,]) >>>>>>>>> ``` >>>>>>>>> >>>>>>>>> and again, it would help for callbacks too, `something( ( , , >>>>>>>>> thirdArg) => {} )` >>>>>>>>> >>>>>>>>> I saw this https://jeffmo.github.io/es-trailing-function-commas/, >>>>>>>>> it seems like a sub-case >>>>>>>>> >>>>>>>>> 2016-05-29 23:07 GMT+02:00 Renki Ivanko <fatalis.erratum at gmail.com >>>>>>>>> >: >>>>>>>>> >>>>>>>>>> One more similarity is that both function parameters and >>>>>>>>>> destructuring allow default values: (foo = 1) vs [foo = 1]. >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Sun, May 29, 2016 at 11:56 PM, Cyril Auburtin < >>>>>>>>>> cyril.auburtin at gmail.com> wrote: >>>>>>>>>> >>>>>>>>>>> Since functions arguments is an array under the hood, they could >>>>>>>>>>> 'more behave the same' >>>>>>>>>>> >>>>>>>>>>> Both function arguments and arrays accept spreading: *[1, 2, >>>>>>>>>>> ...args] * and *fn(1, 2, ...args)* >>>>>>>>>>> >>>>>>>>>>> a function definition like *(,i) => {}*, would be the >>>>>>>>>>> equivalent of *var [,i] = arguments* >>>>>>>>>>> >>>>>>>>>>> an invocation *fn(,,i)* would be the equivalent of *[,,i]* >>>>>>>>>>> >>>>>>>>>>> It's possible with *(...[,i]) => {}, (_,i)=>{} *like Renki >>>>>>>>>>> said, but slightly less simply >>>>>>>>>>> >>>>>>>>>>> Are there possible issues with that 'extension' of function >>>>>>>>>>> syntax? >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> 2016-05-29 21:32 GMT+02:00 Renki Ivanko < >>>>>>>>>>> fatalis.erratum at gmail.com>: >>>>>>>>>>> >>>>>>>>>>>> You could stop with "rare"; having to make up unused names is >>>>>>>>>>>> an obvious smell in comparison. >>>>>>>>>>>> >>>>>>>>>>>> ```js >>>>>>>>>>>> foo(UNUSED1, UNUSED2, x) >>>>>>>>>>>> >>>>>>>>>>>> foo(_, __, x) >>>>>>>>>>>> >>>>>>>>>>>> foo(,, x) >>>>>>>>>>>> >>>>>>>>>>>> foo(...[,, x]) >>>>>>>>>>>> ``` >>>>>>>>>>>> >>>>>>>>>>>> The latter is shorter and more explicit and would not be any >>>>>>>>>>>> more confusing if it became common. >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> On Sun, May 29, 2016 at 8:46 PM, Bob Myers <rtm at gol.com> wrote: >>>>>>>>>>>> >>>>>>>>>>>>> Eliding array elements is not "similar" to eliding function >>>>>>>>>>>>> formal parameters. The latter is extremely rare, hardly readable, >>>>>>>>>>>>> confusing, bug-prone, and unnecessary because there is already a "standard >>>>>>>>>>>>> way" which is to use any old parameter name you want: >>>>>>>>>>>>> >>>>>>>>>>>>> ```js >>>>>>>>>>>>> function foo(UNUSED1, UNUSED2, x) >>>>>>>>>>>>> ```` >>>>>>>>>>>>> >>>>>>>>>>>>> Most linters will not complain, or there are ways to shut them >>>>>>>>>>>>> up if they do. >>>>>>>>>>>>> >>>>>>>>>>>>> If you want to throw away an argument, just throw it away. >>>>>>>>>>>>> >>>>>>>>>>>>> ```js >>>>>>>>>>>>> function skipFirstParam(fn) { return ((first, ...args) => >>>>>>>>>>>>> fn(...args)); } >>>>>>>>>>>>> >>>>>>>>>>>>> `[1,2,3,4].map(skipFirstParam(i => i)); >>>>>>>>>>>>> >>>>>>>>>>>>> ``` >>>>>>>>>>>>> >>>>>>>>>>>>> Or use Renki's solution. >>>>>>>>>>>>> >>>>>>>>>>>>> Bob >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> On Sun, May 29, 2016 at 9:23 PM, Cyril Auburtin < >>>>>>>>>>>>> cyril.auburtin at gmail.com> wrote: >>>>>>>>>>>>> >>>>>>>>>>>>>> Similarly to: >>>>>>>>>>>>>> >>>>>>>>>>>>>> `var [,x,,y] = [1,2,3,4,5,6];` >>>>>>>>>>>>>> >>>>>>>>>>>>>> I think it could be interesting to let a field empty in >>>>>>>>>>>>>> function arguments >>>>>>>>>>>>>> >>>>>>>>>>>>>> `[1,2,3,4].map( (,i) => i )`, `Array.from({length:10}, (,i) >>>>>>>>>>>>>> => i )` >>>>>>>>>>>>>> >>>>>>>>>>>>>> `function test(a,,b) { }` >>>>>>>>>>>>>> >>>>>>>>>>>>>> (but that would alter the current parsing, that doesn't allow >>>>>>>>>>>>>> it) >>>>>>>>>>>>>> >>>>>>>>>>>>>> Currently I often use `_` as a way to mark ignored fields, >>>>>>>>>>>>>> but when there are more than 1 you need another identifier. A standard way >>>>>>>>>>>>>> would be interesting rather >>>>>>>>>>>>>> >>>>>>>>>>>>>> _______________________________________________ >>>>>>>>>>>>>> es-discuss mailing list >>>>>>>>>>>>>> es-discuss at mozilla.org >>>>>>>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>>>>>>> >>>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> _______________________________________________ >>>>>>>>>>>>> es-discuss mailing list >>>>>>>>>>>>> es-discuss at mozilla.org >>>>>>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> es-discuss mailing list >>>>>>>>> es-discuss at mozilla.org >>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> es-discuss mailing list >>>>>>>>> es-discuss at mozilla.org >>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> es-discuss mailing list >>>>>>> es-discuss at mozilla.org >>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>> >>>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160812/74d06d47/attachment-0001.html>
off-topic: I received this nice mail by Bob, this person was the only one to not understand the point of this discussion, why does someone act like that?
ps: He's also wrong in that function(_, _, arg) is allowed, it's not in strict mode, not for arrow functions either
Thanks for that discussion, it'll very likely never make it to the spec,
Most people would read the above as signing off/out of the discussion. Would that it had been so.
There is an English expression that comes to mind here: BEATING A DEAD HORSE.
No one cares about the proposal. It is somewhere between irrelevant, and actively bad--primarily by harming readability. You act as if writing out an unused parameter is somehow a wanton act of waste that is eating into the world's limited supply of available variables.
Minor point, but it is syntactically valid to write function(_, _, arg)
,
so you don't have to "use up another variable binding" with the second
unused parameter.
In case you didn't notice, the proposal is not getting any traction and will never get any traction. Move on.
, Bob
off-topic: I received this nice mail by Bob, this person was the only one to not understand the point of this discussion, why does someone act like that? ------------- > Thanks for that discussion, it'll very likely never make it to the spec, Most people would read the above as signing off/out of the discussion. Would that it had been so. There is an English expression that comes to mind here: BEATING A DEAD HORSE. No one cares about the proposal. It is somewhere between irrelevant, and actively bad--primarily by harming readability. You act as if writing out an unused parameter is somehow a wanton act of waste that is eating into the world's limited supply of available variables. Minor point, but it is syntactically valid to write `function(_, _, arg)`, so you don't have to "use up another variable binding" with the second unused parameter. In case you didn't notice, the proposal is not getting any traction and will never get any traction. Move on. Regards, Bob -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160812/61bd36e9/attachment.html>
Can the moderator please delete this post, since it was private mail never intended for publication. Also, please look at blocking options. Bob
Can the moderator please delete this post, since it was private mail never intended for publication. Also, please look at blocking options. Bob On Fri, Aug 12, 2016 at 4:41 PM, Cyril Auburtin <cyril.auburtin at gmail.com> wrote: > off-topic: I received this nice mail by Bob, this person was the only one > to not understand the point of this discussion, why does someone act like > that? > ------------- > > Thanks for that discussion, it'll very likely never make it to the > spec, > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160812/77188585/attachment.html>
Similarly to:
var [,x,,y] = [1,2,3,4,5,6];
array destructuring, or[a,,b]
array creation,I think it could be interesting to let a field empty in function arguments
by altering the current syntax that doesn't allow it
Most often people use
_
as a way to mark ignored fields, but when (more rarely) there are more than 1 ignored field, you need another identifier. A standard way would be interesting rather