[Issue 7176] New: Lambda => syntax for function and methods too
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Wed Dec 28 05:11:11 PST 2011
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=7176
           Summary: Lambda => syntax for function and methods too
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2011-12-28 05:11:07 PST ---
(From an idea of Timon Gehr)
I think extending the applicability of the new lambda syntax to free
functions/methods is a nice idea, to shorten tiny functions/methods, that are
common enough:
struct C {
    int x;
    int getX() => x;
    int sqrX() => x ^^ 2;
}
Some examples from other languages:
A function to compute the arithmetic mean in Scala 2.7:
def mean(s: Seq[Int]) = s.foldLeft(0)(_+_) / s.size
>From the Ada 2012 changes:
http://www.disca.upv.es/jorge/ae2010/slides/05-3_Language_Tech_Schonberg_Towards_Ada_2012.pdf
> To simplify the writing of pre/postconditions and predicates, allow parametrized expressions (aka function bodies in package specs):
function Cube (X : integer) is (X ** 3);
-- 
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