Expression-bodied functions
Enamex via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jan 2 07:04:15 PST 2016
On Friday, 1 January 2016 at 00:27:49 UTC, ZombineDev wrote:
> 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
IMHO, anything like that is just a tangential 'fix' to the fact
that D's design rests on commands like 'return' to leave scope
and return values.
Something like
auto add(auto x, auto y) { x + y }
would be much more wholesome IMO. (The 'funcName(auto arg)'
syntax is just a convenience suggestions; the important part is
'{ x + y }').
That said, it does fix something that 'alias' should've been able
to do from the beginning. I'm not sure what else but I think
there other places where alias needs '= I!(stuff)' identity
template to accept the 'stuff'.
More information about the Digitalmars-d
mailing list