Re: Proposal: Placeholder operator

2019-01-11 Thread Tab Atkins Jr.
On Fri, Jan 11, 2019 at 6:42 AM Sultan  wrote:
> >empty space with a comma?
>
> I think that only works with trailing params. For example this is not 
> possible:
>
> const foo = (a,  , c) => {}

It doesn't even "work" with trailing params. Function arglists can
*contain* a trailing comma, it's just ignored and does nothing. `const
foo = (a, b, )=>a+b` still has a .length == 2, and `(a, b, ,)=>a+b` is
just invalid syntax. The trailing comma is just allowed so you can
format a long arglist onto separate lines, and don't have to remember
that the last argument doesn't have a comma.

> >Today, you can write: const foo = (a, b, _) => {}
>
> However that does throw with:
>
> const foo = (a, _, _) => {}

Yup, I've run into that problem before, and had to hack around by
using `_1` for the second ignored arg. It's rare/niche enough that I'm
not sure it's worth solving, but I do acknowledge it as an annoyance.

> >You can already write: const [ , setState] = useState(0)
>
> Thanks i forgot about that.

Yeah, using holes *works*, but it's definitely harder to read than using _.

And the fact that the last trailing , does *not* create a hole isn't
relevant for destructuring, but it would be relevant and confusing for
function-arity if we allowed holes in arglists. That is,
`[1,2,].length` returns 2 list, while `[1,2,,].length` returns 3. If
we get pattern-matching and array literals can do strict length
checking, it would also become relevant and confusing. (But that's
several stacked "if"s!)

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


Re: Proposal: Placeholder operator

2019-01-11 Thread Sultan
>empty space with a comma?

I think that only works with trailing params. For example this is not
possible:

const foo = (a,  , c) => {}

>Today, you can write: const foo = (a, b, _) => {}

However that does throw with:

const foo = (a, _, _) => {}

>You can already write: const [ , setState] = useState(0)

Thanks i forgot about that.

On Fri, Jan 11, 2019 at 5:31 PM Claude Pache  wrote:

>
>
> > Le 11 janv. 2019 à 14:02, Sultan  a écrit :
> >
> > Placeholder operator: !
> >
> > Use in function parameters(maintains arity without creating a named
> binding):
> >
> > const foo = (a, b, !) => {}
>
> Today, you can write:
>
> ```js
> const foo = (a, b, _) => { }
> ```
>
> Is the complexity added to the language worth the feature?
>
> >
> > Use in de-structuring(allows you to capture further along a tuple
> without creating a named binding):
> >
> > const [!, setState] = useState(0)
>
> You can already write:
>
> ```js
> const [ , setState] = useState(0)
> ```
>
> —Claude
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Proposal: Placeholder operator

2019-01-11 Thread Claude Pache


> Le 11 janv. 2019 à 14:02, Sultan  a écrit :
> 
> Placeholder operator: !
> 
> Use in function parameters(maintains arity without creating a named binding):
> 
> const foo = (a, b, !) => {}

Today, you can write:

```js
const foo = (a, b, _) => { }
```

Is the complexity added to the language worth the feature?

> 
> Use in de-structuring(allows you to capture further along a tuple without 
> creating a named binding):
> 
> const [!, setState] = useState(0)

You can already write:

```js
const [ , setState] = useState(0)
```

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


Re: Re: Proposal: Placeholder operator

2019-01-11 Thread dante federici
Any reason you don't like the empty space with a comma? I also don't, but
that's what it is now:

```js
arr.map(( , index) => ...)
```

Also wouldn't mind ? or *, since I associate ! with "not" as a unary
operator, but "*" isn't a unary in JS.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss