Anonymous function syntax

Lutger Blijdestijn lutger.blijdestijn at gmail.com
Thu Sep 22 13:10:40 PDT 2011


Andrei Alexandrescu wrote:

> On 9/22/11 10:42 AM, pillsy wrote:
>> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s
>> article
>>> On 9/22/11 1:47 AM, Max Klyga wrote:
>>>> Actually Scala doesn't need type declarations in labmda literals. Most
>>>> of the time argument types are infered.
>>
>>> Already does. We're looking for a briefer syntax.
>>
>> What is the problem with just inferring the `return`, allowing you to
>> replace
>>
>>       (a,b) { return a + b; }
>>
>> with
>>
>>      (a, b) { a + b; }
>>
>> This seems competitive with the other syntaxes for brevity, but ISTR
>> there was some objection to doing things that way.
> 
> The objection is that it introduces a number of questions:
> 
> 1. How about using that syntax in regular functions?
> 
> 2. What if the lambda wants to actually evaluate the expression but
> return void?

As an alternative, a brief syntax could just be restricted to lambda 
expressions because we already have complete function literals for 
statements, unlike python for example. A void returning function is only 
used for side-effects, I am not be bothered at all to have to use full 
punctuation for that.

(a, b) { a + b } or (a, b) => a + b would be sweet :)



More information about the Digitalmars-d mailing list