Swift style syntax

Alexander Jones alex at weej.com
Sun Oct 11 21:51:02 UTC 2015


IMO this is a good idea. When it's abundantly clear from context, I've
already been naming my arrow function params _ if singular, and _1, _2 etc
if several. As always, picking some punctuation straight from the scarce
and sacred set of remaining ASCII symbols is going to be tricky. (If only
we could just go APL on this!)

On 11 October 2015 at 16:45, Mohsen Azimi <me at azimi.me> wrote:

> Is it possible to extend JavaScript syntax to support Swift style block
> syntax[1]?
>
> In Swift it's possible to omit return keyword
> ```
>
>    1. reversed = names.sort( { s1, s2 in s1 > s2 } )
>
> ```
>
> or omit argument declaration like this:
>
> ```
>
>    1. reversed = names.sort( { $0 > $1 } )
>
> ```
>
> or apply an operator to arguments of a function
>
> ```
>
>    1. reversed = names.sort(>)
>
> ```
> We have the first feature in ES2015 already:
>
> ```
> let sorted = names.sort((a, b)=> a > b);
> ```
>
> But for omitting argument declaration we need to find an alternative to
> $0, $1... since those are valid variable names in JS. Maybe we can use #0,
> #1... instead.
>
> This is very useful for functional programming aspect of JS. For example
> in a filter function:
>
> ```
> let passed = objs.filter(#0.passed)
> ```
>
>
>
>
> [1][
> https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html
> ]
>
> _______________________________________________
> 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/20151011/07b8d947/attachment.html>


More information about the es-discuss mailing list