Functional Programming with D

qznc qznc at web.de
Sat Apr 13 10:24:19 PDT 2013


Sat, 13 Apr 2013 17:46:10 +0200: Timon Gehr wrote

> On 04/13/2013 05:25 PM, qznc wrote:
>> Sat, 13 Apr 2013 15:03:51 +0200: Vladimir Panteleev wrote
>>> On Saturday, 13 April 2013 at 12:29:29 UTC, qznc wrote:
>>>> While there is no syntactic sugar,
>>>
>>> What about lambdas?
>>>
>>> http://dlang.org/expression.html#Lambda
>>
>> Oh. I forgot about those. Thanks!
>>
>> The syntactic sugar seems to be quite diverse, since most of the
>> FunctionLiteral is optional. As far as I understand the docs, all the
>> following forms are valid?
>>
>> auto square1 = function int (int x) { return x*x; };
> 
> yes.
> 
>> auto square2 = function (int x) { return x*x; };
> 
> yes.
> 
>> auto square3 = (int x) { return x*x; };
> 
> yes.
> 
>> auto square4 = int (int x) { return x*x; };
> 
> no.
> 
>> auto square5 = (int x) => x*x;
> 
> yes.
> 
>> auto square6 = x => x*x;
>>
>>
> no. (valid grammar, but you need some type annotation.)
> 
> But there are more, like function(int x)=>x*x.

That one is not documented in the grammar. A Lambda does not start with 
"function" and a FunctionLiteral does not contain "=>". What is it?


More information about the Digitalmars-d-announce mailing list