Swift style syntax
Isiah Meadows
isiahmeadows at gmail.com
Mon Oct 12 06:40:27 UTC 2015
Interesting trick, Andrea. Never thought of that before.
On Mon, Oct 12, 2015, 02:31 Andrea Giammarchi <andrea.giammarchi at gmail.com>
wrote:
> ... sort of (no pun intended)
>
> ```js
> let sorted = names.sort((...$) => $[0] > $[1]);
> ```
>
> Regards
>
> On Mon, Oct 12, 2015 at 2:58 AM, Frankie Bagnardi <f.bagnardi at gmail.com>
> wrote:
>
>> I don't think there's much value in this. Also sort is a bad example
>> because it'd look like this, and there's no nifty shortcut answer to it.
>>
>> ```js
>> names.sort((a, b) => a < b ? 1 : a > b ? -1 : 0);
>> ```
>>
>> In most cases you save a couple characters, but you can just use
>> x/y/a/b/f/g/n/xs/xss for variable names in arrow functions instead of the
>> $0 (which would likely be \0 in js).
>>
>>
>>
>> On Sun, Oct 11, 2015 at 3:26 PM, Caitlin Potter <caitpotter88 at gmail.com>
>> wrote:
>>
>>> 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
>>>> ```
>>>>
>>>> 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
>>>>
>>>>
>>> _______________________________________________
>>> 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
>>>
>>>
>>
>> _______________________________________________
>> 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/20151012/e4ea4f17/attachment.html>
More information about the es-discuss
mailing list