Swift style syntax

Caitlin Potter caitpotter88 at gmail.com
Sun Oct 11 22:26:54 UTC 2015


In the case of sorting, are arrow functions not good enough? Or are we really asking for full continuation support

> On Oct 11, 2015, at 5:51 PM, Alexander Jones <alex at weej.com> wrote:
> 
> 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 
>> ```
>> reversed = names.sort( { s1, s2 in s1 > s2 } )
>> ```
>> 
>> or omit argument declaration like this:
>> 
>> ```
>> reversed = names.sort( { $0 > $1 } )
>> ```
>> 
>> or apply an operator to arguments of a function 
>> 
>> ```
>> 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
> 
> _______________________________________________
> 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/fe1b8702/attachment-0001.html>


More information about the es-discuss mailing list