Re: Syntax Proposal: Anonymous Arguments

2016-09-28 Thread Tab Atkins Jr.
On Fri, Sep 23, 2016 at 10:38 AM, Kenneth Powers  wrote:
> I have a proposal for new syntax in ES inspired by the placeholder syntax in
> Scala Functions.
>
> Essentially, the idea would be to allow anonymous arguments. The most simple
> example would be a function which takes one argument (as far as the
> programmer is concerned):
>
> [1, 2, 3].map(@ + 1)
>
> This would be the same thing as:
>
> [1, 2, 3].map(n => n + 1)
>
> Just like in Scala, an anonymous function is created. This concept can be
> further extended in ES:
>
> [1, 2, 3].reduce(@0 + @1, 0)
>
> Which would be the same thing as:
>
>[1, 2, 3].reduce((sum, n) => sum + n, 0)
>
> Thoughts?

While I like really concise callbacks for simple cases like this, the
win over arrow functions is *so tiny* here.  map(@+1) vs map(x=>x+1)
is *3 characters* different; map(@0+@1) vs map((x,y)=>x+y) is 5.
Having to learn a new syntax for tiny functions that only gains an
extremely miniscule benefit in terms of code size is an extremely hard
sell.

Compound this with the fact that the @ glyph is already spoken for,
and you have an extreme uphill battle to deal with.

I suggest just living with the few extra characters that arrow
functions impose, and being happy we no longer have to type out
"function ... { return }". ^_^

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


Re: Syntax Proposal: Anonymous Arguments

2016-09-26 Thread Isiah Meadows
I agree. Also, in particular, Scala's partial application syntax does tend
to confuse newcomers, and can easily border on the same obfuscation level
as point free style in Haskell for similar reasons (which is easier to
understand, `owl = (.) . (.)` or `owl f g x y = f (g x y)`). Also, I'm not
sure such syntax is actually necessary. If anything, curried operator
functions like what Python has (the operator module), but hopefully more
concise, would completely solve most of this, and could probably start as
an easy trivial userland library. (Note that Lodash and Underscore both
already provide some of these uncurried.)

On Mon, Sep 26, 2016, 06:59 Claude Pache  wrote:

> Le 23 sept. 2016 à 20:35, Kenneth Powers  a écrit :
>
> As for resolving ambiguity, why not just do what Scala does
> ?
> It would seem to me that nesting these functions would be a sign you need
> to refactor anyway.
>
>
> Concretely, when you write:
>
> ```js
> listOfNumbers.map(Math.floor(@) + 1)
> ```
>
> what does it mean:
>
> ```js
> _ => listOfNumbers.map(Math.floor(_) + 1) // (1)
> listOfNumbers.map(_ => Math.floor(_) + 1) // (2)
> listOfNumbers.map(Math.floor(_ => _) + 1) // (3)
> ```
>
> ? Although the most reasonable interpretation for a human would be (2),
> because the parser is unable to read your mind or to make a qualitative
> distinction between `listOfNumbers.map ` and `Math.floor` (both are just
> functions), it will most probably misinterpret it as (3).
>
> That syntax looks like an attractive nuisance to me.
>
> —Claude
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Syntax Proposal: Anonymous Arguments

2016-09-26 Thread Claude Pache

> Le 23 sept. 2016 à 20:35, Kenneth Powers  a écrit :
> 
> As for resolving ambiguity, why not just do what Scala does 
> ?
>  It would seem to me that nesting these functions would be a sign you need to 
> refactor anyway. 

Concretely, when you write:

```js
listOfNumbers.map(Math.floor(@) + 1)
```

what does it mean:

```js
_ => listOfNumbers.map(Math.floor(_) + 1) // (1)
listOfNumbers.map(_ => Math.floor(_) + 1) // (2)
listOfNumbers.map(Math.floor(_ => _) + 1) // (3)
```

? Although the most reasonable interpretation for a human would be (2), because 
the parser is unable to read your mind or to make a qualitative distinction 
between `listOfNumbers.map ` and `Math.floor` (both are just functions), it 
will most probably misinterpret it as (3).

That syntax looks like an attractive nuisance to me.

—Claude

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


Re: Syntax Proposal: Anonymous Arguments

2016-09-24 Thread Bob Myers
How would I write

```
a => b => a + b
```

I could write

```
a => a + @
```

but that only gets me half-way.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Syntax Proposal: Anonymous Arguments

2016-09-23 Thread Kenneth Powers
Of course, decorators. # was actually my original idea when I was
discussing this with co-workers. One of them suggested <>, which reminds me
of the multi-character proposal for pipelining (|>, I believe). In the case
of indexed shorthand argument names as in my original proposal (and bash,
and swift) something like <0>, <1>, <2>, etc may work.

I also got this directly in my inbox (I think he forgot to reply-all):

> Might be interesting if it included template strings...

>return weeks.map(`Week ${@ + 1}`);

I think template strings are a really interesting side effect of this
proposal (shouldn't require any additions to the actual proposal), even
without inline operations. Consider:

people.map(`Name: ${<>}`);

Which desugars to:

people.map(name => `Name: ${name}`);

On Fri, Sep 23, 2016 at 5:47 PM Alan Johnson  wrote:

> I found the underscores in Scala confusing at first, for sure. Of course,
> after a couple months working with the language, you feel right at home.
>
> Worth noting that Swift does something kind of like Bash, with indexed 
> shorthand
> argument names
> ,
> which lets you can reuse your anonymous argument. It comes in handy when
> you don’t want to clutter code with names for things that are obvious. But
> I think it only works within curly braces.
>
> Obviously, both variations require judgment of knowing when the meaning of
> the argument is self-evident.
>
>
>
> On Sep 23, 2016, at 16:31, Jordan Harband  wrote:
>
> @ is currently reserved for decorators, # currently for private fields.
> There aren't a lot of compelling syntax options left, to be sure.
>
> On Fri, Sep 23, 2016 at 11:35 AM, Kenneth Powers 
> wrote:
>
>> What proposal is "@" reserved for, by chance? I was trying to pick
>> something that both wasn't used and can't be the name of a variable (e.g.,
>> underscore). I saw another proposal for "?" for partially applying
>> functions, but that would be potentially ambiguous with the ternary
>> operator.
>>
>> As for resolving ambiguity, why not just do what Scala does
>> ?
>> It would seem to me that nesting these functions would be a sign you need
>> to refactor anyway.
>>
>> As far as meriting its own syntax, that's why I referenced another
>> language where the implementors found that it did merit its own syntax
>> (though the underscore in Scala also does a lot more).
>>
>> On Fri, Sep 23, 2016 at 2:00 PM, Jordan Harband  wrote:
>>
>>> In Scala, the ambiguity of the underscore causes lots of confusion when
>>> you have nested functions - how is that handled in your proposal?
>>>
>>> Bear in mind, I think it's a tough argument that `@ + 1` is so much
>>> better than `n => n + 1` that it warrants its own syntax.
>>>
>>> Separately, the "@" is reserved for an existing proposal, so you'd have
>>> to come up with different syntax anyways.
>>>
>>> On Fri, Sep 23, 2016 at 10:38 AM, Kenneth Powers 
>>> wrote:
>>>
 I have a proposal for new syntax in ES inspired by the placeholder
 syntax in Scala Functions
 
 .

 Essentially, the idea would be to allow anonymous arguments. The most
 simple example would be a function which takes one argument (as far as the
 programmer is concerned):

 [1, 2, 3].map(@ + 1)

 This would be the same thing as:

 [1, 2, 3].map(n => n + 1)

 Just like in Scala, an anonymous function is created. This concept can
 be further extended in ES:

 [1, 2, 3].reduce(@0 + @1, 0)

 Which would be the same thing as:

[1, 2, 3].reduce((sum, n) => sum + n, 0)

 Thoughts?

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


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


Re: Syntax Proposal: Anonymous Arguments

2016-09-23 Thread Alan Johnson
I found the underscores in Scala confusing at first, for sure. Of course, after 
a couple months working with the language, you feel right at home.

Worth noting that Swift does something kind of like Bash, with indexed 
shorthand argument names 
,
 which lets you can reuse your anonymous argument. It comes in handy when you 
don’t want to clutter code with names for things that are obvious. But I think 
it only works within curly braces.

Obviously, both variations require judgment of knowing when the meaning of the 
argument is self-evident.


> On Sep 23, 2016, at 16:31, Jordan Harband  wrote:
> 
> @ is currently reserved for decorators, # currently for private fields. There 
> aren't a lot of compelling syntax options left, to be sure.
> 
> On Fri, Sep 23, 2016 at 11:35 AM, Kenneth Powers  > wrote:
> What proposal is "@" reserved for, by chance? I was trying to pick something 
> that both wasn't used and can't be the name of a variable (e.g., underscore). 
> I saw another proposal for "?" for partially applying functions, but that 
> would be potentially ambiguous with the ternary operator.
> 
> As for resolving ambiguity, why not just do what Scala does 
> ?
>  It would seem to me that nesting these functions would be a sign you need to 
> refactor anyway. 
> 
> As far as meriting its own syntax, that's why I referenced another language 
> where the implementors found that it did merit its own syntax (though the 
> underscore in Scala also does a lot more).
> 
> On Fri, Sep 23, 2016 at 2:00 PM, Jordan Harband  > wrote:
> In Scala, the ambiguity of the underscore causes lots of confusion when you 
> have nested functions - how is that handled in your proposal?
> 
> Bear in mind, I think it's a tough argument that `@ + 1` is so much better 
> than `n => n + 1` that it warrants its own syntax.
> 
> Separately, the "@" is reserved for an existing proposal, so you'd have to 
> come up with different syntax anyways.
> 
> On Fri, Sep 23, 2016 at 10:38 AM, Kenneth Powers  > wrote:
> I have a proposal for new syntax in ES inspired by the placeholder syntax in 
> Scala Functions 
> .
> 
> Essentially, the idea would be to allow anonymous arguments. The most simple 
> example would be a function which takes one argument (as far as the 
> programmer is concerned):
> 
> [1, 2, 3].map(@ + 1)
> 
> This would be the same thing as:
> 
> [1, 2, 3].map(n => n + 1)
> 
> Just like in Scala, an anonymous function is created. This concept can be 
> further extended in ES:
> 
> [1, 2, 3].reduce(@0 + @1, 0)
> 
> Which would be the same thing as:
> 
>[1, 2, 3].reduce((sum, n) => sum + n, 0)
> 
> Thoughts?
> 
> ___
> es-discuss mailing list
> es-discuss@mozilla.org 
> https://mail.mozilla.org/listinfo/es-discuss 
> 
> 
> 
> 
> 
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

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


RE: Syntax Proposal: Anonymous Arguments

2016-09-23 Thread doodad-js Admin
Should not “private fields” be a decorator ?

 

From: Jordan Harband [mailto:ljh...@gmail.com] 
Sent: Friday, September 23, 2016 4:32 PM
To: Kenneth Powers <k...@kenpowers.net>
Cc: es-discuss <es-discuss@mozilla.org>
Subject: Re: Syntax Proposal: Anonymous Arguments

 

@ is currently reserved for decorators, # currently for private fields. There 
aren't a lot of compelling syntax options left, to be sure.

 

On Fri, Sep 23, 2016 at 11:35 AM, Kenneth Powers <k...@kenpowers.net 
<mailto:k...@kenpowers.net> > wrote:

What proposal is "@" reserved for, by chance? I was trying to pick something 
that both wasn't used and can't be the name of a variable (e.g., underscore). I 
saw another proposal for "?" for partially applying functions, but that would 
be potentially ambiguous with the ternary operator.

 

As for resolving ambiguity, why not just do what Scala does 
<http://stackoverflow.com/questions/19916169/scala-arguments-of-nested-lambdas-with-short-syntax/19917720>
 ? It would seem to me that nesting these functions would be a sign you need to 
refactor anyway. 

 

As far as meriting its own syntax, that's why I referenced another language 
where the implementors found that it did merit its own syntax (though the 
underscore in Scala also does a lot more).

 

On Fri, Sep 23, 2016 at 2:00 PM, Jordan Harband <ljh...@gmail.com 
<mailto:ljh...@gmail.com> > wrote:

In Scala, the ambiguity of the underscore causes lots of confusion when you 
have nested functions - how is that handled in your proposal?

 

Bear in mind, I think it's a tough argument that `@ + 1` is so much better than 
`n => n + 1` that it warrants its own syntax.

 

Separately, the "@" is reserved for an existing proposal, so you'd have to come 
up with different syntax anyways.

 

On Fri, Sep 23, 2016 at 10:38 AM, Kenneth Powers <k...@kenpowers.net 
<mailto:k...@kenpowers.net> > wrote:

I have a proposal for new syntax in ES inspired by the placeholder syntax in 
Scala Functions 
<http://docs.scala-lang.org/overviews/quasiquotes/expression-details.html#function>
 .

 

Essentially, the idea would be to allow anonymous arguments. The most simple 
example would be a function which takes one argument (as far as the programmer 
is concerned):

 

[1, 2, 3].map(@ + 1)

 

This would be the same thing as:

 

[1, 2, 3].map(n => n + 1)

 

Just like in Scala, an anonymous function is created. This concept can be 
further extended in ES:

 

[1, 2, 3].reduce(@0 + @1, 0)

 

Which would be the same thing as:

 

   [1, 2, 3].reduce((sum, n) => sum + n, 0)

 

Thoughts?

 

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

 

 

 

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


Re: Syntax Proposal: Anonymous Arguments

2016-09-23 Thread Rick Waldron
What does this mean:


let f = @;




On Fri, Sep 23, 2016 at 4:32 PM Jordan Harband  wrote:

> @ is currently reserved for decorators, # currently for private fields.
> There aren't a lot of compelling syntax options left, to be sure.
>
> On Fri, Sep 23, 2016 at 11:35 AM, Kenneth Powers 
> wrote:
>
>> What proposal is "@" reserved for, by chance? I was trying to pick
>> something that both wasn't used and can't be the name of a variable (e.g.,
>> underscore). I saw another proposal for "?" for partially applying
>> functions, but that would be potentially ambiguous with the ternary
>> operator.
>>
>> As for resolving ambiguity, why not just do what Scala does
>> ?
>> It would seem to me that nesting these functions would be a sign you need
>> to refactor anyway.
>>
>> As far as meriting its own syntax, that's why I referenced another
>> language where the implementors found that it did merit its own syntax
>> (though the underscore in Scala also does a lot more).
>>
>> On Fri, Sep 23, 2016 at 2:00 PM, Jordan Harband  wrote:
>>
>>> In Scala, the ambiguity of the underscore causes lots of confusion when
>>> you have nested functions - how is that handled in your proposal?
>>>
>>> Bear in mind, I think it's a tough argument that `@ + 1` is so much
>>> better than `n => n + 1` that it warrants its own syntax.
>>>
>>> Separately, the "@" is reserved for an existing proposal, so you'd have
>>> to come up with different syntax anyways.
>>>
>>> On Fri, Sep 23, 2016 at 10:38 AM, Kenneth Powers 
>>> wrote:
>>>
 I have a proposal for new syntax in ES inspired by the placeholder
 syntax in Scala Functions
 
 .

 Essentially, the idea would be to allow anonymous arguments. The most
 simple example would be a function which takes one argument (as far as the
 programmer is concerned):

 [1, 2, 3].map(@ + 1)

 This would be the same thing as:

 [1, 2, 3].map(n => n + 1)

 Just like in Scala, an anonymous function is created. This concept can
 be further extended in ES:

 [1, 2, 3].reduce(@0 + @1, 0)

 Which would be the same thing as:

[1, 2, 3].reduce((sum, n) => sum + n, 0)

 Thoughts?

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


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


Re: Syntax Proposal: Anonymous Arguments

2016-09-23 Thread Jordan Harband
@ is currently reserved for decorators, # currently for private fields.
There aren't a lot of compelling syntax options left, to be sure.

On Fri, Sep 23, 2016 at 11:35 AM, Kenneth Powers  wrote:

> What proposal is "@" reserved for, by chance? I was trying to pick
> something that both wasn't used and can't be the name of a variable (e.g.,
> underscore). I saw another proposal for "?" for partially applying
> functions, but that would be potentially ambiguous with the ternary
> operator.
>
> As for resolving ambiguity, why not just do what Scala does
> ?
> It would seem to me that nesting these functions would be a sign you need
> to refactor anyway.
>
> As far as meriting its own syntax, that's why I referenced another
> language where the implementors found that it did merit its own syntax
> (though the underscore in Scala also does a lot more).
>
> On Fri, Sep 23, 2016 at 2:00 PM, Jordan Harband  wrote:
>
>> In Scala, the ambiguity of the underscore causes lots of confusion when
>> you have nested functions - how is that handled in your proposal?
>>
>> Bear in mind, I think it's a tough argument that `@ + 1` is so much
>> better than `n => n + 1` that it warrants its own syntax.
>>
>> Separately, the "@" is reserved for an existing proposal, so you'd have
>> to come up with different syntax anyways.
>>
>> On Fri, Sep 23, 2016 at 10:38 AM, Kenneth Powers 
>> wrote:
>>
>>> I have a proposal for new syntax in ES inspired by the placeholder
>>> syntax in Scala Functions
>>> 
>>> .
>>>
>>> Essentially, the idea would be to allow anonymous arguments. The most
>>> simple example would be a function which takes one argument (as far as the
>>> programmer is concerned):
>>>
>>> [1, 2, 3].map(@ + 1)
>>>
>>> This would be the same thing as:
>>>
>>> [1, 2, 3].map(n => n + 1)
>>>
>>> Just like in Scala, an anonymous function is created. This concept can
>>> be further extended in ES:
>>>
>>> [1, 2, 3].reduce(@0 + @1, 0)
>>>
>>> Which would be the same thing as:
>>>
>>>[1, 2, 3].reduce((sum, n) => sum + n, 0)
>>>
>>> Thoughts?
>>>
>>> ___
>>> es-discuss mailing list
>>> es-discuss@mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
>>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Syntax Proposal: Anonymous Arguments

2016-09-23 Thread Kenneth Powers
What proposal is "@" reserved for, by chance? I was trying to pick
something that both wasn't used and can't be the name of a variable (e.g.,
underscore). I saw another proposal for "?" for partially applying
functions, but that would be potentially ambiguous with the ternary
operator.

As for resolving ambiguity, why not just do what Scala does
?
It would seem to me that nesting these functions would be a sign you need
to refactor anyway.

As far as meriting its own syntax, that's why I referenced another language
where the implementors found that it did merit its own syntax (though the
underscore in Scala also does a lot more).

On Fri, Sep 23, 2016 at 2:00 PM, Jordan Harband  wrote:

> In Scala, the ambiguity of the underscore causes lots of confusion when
> you have nested functions - how is that handled in your proposal?
>
> Bear in mind, I think it's a tough argument that `@ + 1` is so much better
> than `n => n + 1` that it warrants its own syntax.
>
> Separately, the "@" is reserved for an existing proposal, so you'd have to
> come up with different syntax anyways.
>
> On Fri, Sep 23, 2016 at 10:38 AM, Kenneth Powers 
> wrote:
>
>> I have a proposal for new syntax in ES inspired by the placeholder syntax
>> in Scala Functions
>> 
>> .
>>
>> Essentially, the idea would be to allow anonymous arguments. The most
>> simple example would be a function which takes one argument (as far as the
>> programmer is concerned):
>>
>> [1, 2, 3].map(@ + 1)
>>
>> This would be the same thing as:
>>
>> [1, 2, 3].map(n => n + 1)
>>
>> Just like in Scala, an anonymous function is created. This concept can be
>> further extended in ES:
>>
>> [1, 2, 3].reduce(@0 + @1, 0)
>>
>> Which would be the same thing as:
>>
>>[1, 2, 3].reduce((sum, n) => sum + n, 0)
>>
>> Thoughts?
>>
>> ___
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Syntax Proposal: Anonymous Arguments

2016-09-23 Thread Jordan Harband
In Scala, the ambiguity of the underscore causes lots of confusion when you
have nested functions - how is that handled in your proposal?

Bear in mind, I think it's a tough argument that `@ + 1` is so much better
than `n => n + 1` that it warrants its own syntax.

Separately, the "@" is reserved for an existing proposal, so you'd have to
come up with different syntax anyways.

On Fri, Sep 23, 2016 at 10:38 AM, Kenneth Powers  wrote:

> I have a proposal for new syntax in ES inspired by the placeholder syntax
> in Scala Functions
> 
> .
>
> Essentially, the idea would be to allow anonymous arguments. The most
> simple example would be a function which takes one argument (as far as the
> programmer is concerned):
>
> [1, 2, 3].map(@ + 1)
>
> This would be the same thing as:
>
> [1, 2, 3].map(n => n + 1)
>
> Just like in Scala, an anonymous function is created. This concept can be
> further extended in ES:
>
> [1, 2, 3].reduce(@0 + @1, 0)
>
> Which would be the same thing as:
>
>[1, 2, 3].reduce((sum, n) => sum + n, 0)
>
> Thoughts?
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Syntax Proposal: Anonymous Arguments

2016-09-23 Thread Kenneth Powers
I have a proposal for new syntax in ES inspired by the placeholder syntax
in Scala Functions

.

Essentially, the idea would be to allow anonymous arguments. The most
simple example would be a function which takes one argument (as far as the
programmer is concerned):

[1, 2, 3].map(@ + 1)

This would be the same thing as:

[1, 2, 3].map(n => n + 1)

Just like in Scala, an anonymous function is created. This concept can be
further extended in ES:

[1, 2, 3].reduce(@0 + @1, 0)

Which would be the same thing as:

   [1, 2, 3].reduce((sum, n) => sum + n, 0)

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