Functional Programming with D
Timon Gehr
timon.gehr at gmx.ch
Sat Apr 13 08:46:10 PDT 2013
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.
More information about the Digitalmars-d-announce
mailing list