Expression-bodied functions
ZombineDev via Digitalmars-d
digitalmars-d at puremagic.com
Thu Dec 31 16:27:49 PST 2015
On Thursday, 31 December 2015 at 17:15:16 UTC, Gabriel Garcia
wrote:
> Hello all (: This is my first post here.
>
> I don't know if this has been proposed before. Probably, it has
> been. Either way...
>
> https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6#expression-bodied-function-members
>
> Given D's tendency toward expression-oriented (or functional,
> whatever) programming, this seems like a logical addition to
> the language to me.
>
> Cheers.
By the way, a very similar language feature was approved and
implemented for the upcomming DMD 2.070 release. It allows you to
use a short syntax for function templates:
alias add = (a, b) => a + b;
// Shorthand for:
// auto add(T1, T2)(T1 a, T2 b) { return a + b; }
IFTI makes it look like a regular function call:
writeln(add(3, 4.5));
It works for free functions, but I'm not sure if it would also
work for member-functions (methods).
https://issues.dlang.org/show_bug.cgi?id=12421
http://dlang.org/spec/declaration.html#AliasDeclaration
(The relevant part is:
AliasDeclarationY:
Identifier TemplateParametersopt = FunctionLiteral)
https://github.com/D-Programming-Language/dmd/commit/dbba59cadafe540c0c98d69ac867173335e145cd
More information about the Digitalmars-d
mailing list