C++11 lambdas

Jakob Praher jp at hapra.at
Sun Mar 14 11:02:40 PDT 2010


Dear Rémi,

I argumented this on the closures-dev list in similar ways:
*
http://mail.openjdk.java.net/pipermail/closures-dev/2009-November/000278.html
*
http://mail.openjdk.java.net/pipermail/closures-dev/2009-November/000281.html

Yet I like your idea of lambdas and I also mentioned that D allows for
similar construct [1] (see the third alternative for FuncionLiteral):

    FunctionLiteral:
        function Typeopt ParameterAttributes opt FunctionBody
        delegate Typeopt ParameterAttributes opt FunctionBody
        ParameterAttributes FunctionBody
        FunctionBody

    ParameterAttributes:
        Parameters
        Parameters FunctionAttributes


So from myside: I like the idea!

-- Jakob

Am 14.03.10 17:14, schrieb Rémi Forax:
>
> Yes, seeing that I wonder if we are not going in the wrong direction by 
> trying
> to protect lambda and function type by a # or some enclosing parens.
>
> Why not trying something simpler ?
>
>
> A function that takes an int and returns an int:
> int(int)
>
> A function that takes an int and returns nothing:
> void(int)
>
> A function that takes two ints and returns an int:
> int(int, int)
>
> A function that throws an Exception:
> int(int) throws Exception
>
> A function that takes a function that throws an Exception:
> int(int(int) throws Exception)
>
> A function that throws an Exception and takes a function
> int(int(int)) throws Exception
>
> A function that takes an int and returns a function that returns an int
> int() (int)
>
> curry!
> R() throws E (R(A) throws E, A) curry = ...
>
> Grammar:
> ResultType ( TypeList ) throws ExceptionList
>
>
> And removing the # in the lambda syntax:
>
> int(int) fun = (int x) (x);  // lambda expression
> int(int) fun = (int x) { return x; };  // lambda block
>
> A method that returns a lambda:
> int(int,int) plus() {
>    return (int x, int y) (x+y);
> }
>
> A method that takes two function types and returns a lambda:
> int(int,int) filter(int(int) filter, int(int,int) operation) {
>    return (int x, int y) {
>      return operation.(filter.(x), filter.(y));
>    };
> }
>
>
> Rémi
>
>
>   



More information about the lambda-dev mailing list