[Issue 7176] Lambda => syntax for function and methods too

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 20 07:15:31 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=7176


Nick Treleaven <ntrel-public at yahoo.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ntrel-public at yahoo.co.uk


--- Comment #16 from Nick Treleaven <ntrel-public at yahoo.co.uk> 2013-03-20 07:15:30 PDT ---
(In reply to comment #7)
> I could really have a use for this. I have a lot of methods that just returns a
> single expression.

I thought I'd add some hard data on this. There are quite a lot of these in
Phobos (edited results to only show larger count items):

$ git grep -Ec '\{\s*return\b' std/
std/algorithm.d:77
std/cpuid.d:27
std/format.d:35
std/functional.d:37
std/math.d:31
std/range.d:86
std/regex.d:44
std/traits.d:71
std/typecons.d:54
std/variant.d:23
std/xml.d:24

Admittedly, some of these may be false positives for e.g. lambdas, but a quick
scan through the results shows they are almost all one line function/method
definitions. I think this demonstrates a significant use case for the proposed
syntax.

> Another idea would be to allow optional braces for methods and functions, just
> as for if-statements.

That might not be ideal syntax with template constraints:
void foo(T)(T v) if (isFoo!T) writeln(v);
void foo(T)(T v) if (isFoo!T) => writeln(v);

The second syntax is clearer in distinguishing the constraint from if statement
syntax IMO.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list