Syntax Proposal: Anonymous Arguments

Alan Johnson alan at breakrs.com
Fri Sep 23 21:47:01 UTC 2016


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 <https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html>, 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 <ljharb at gmail.com> 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 <ken at kenpowers.net <mailto:ken at 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 <ljharb at gmail.com <mailto:ljharb at 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 <ken at kenpowers.net <mailto:ken at 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 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/20160923/eb792b0d/attachment-0001.html>


More information about the es-discuss mailing list