2 Replies Latest reply on Jul 14, 2010 7:44 AM by richard.szalay

    Lambda expressions and compiler extensions

    richard.szalay Level 1

      Hi guys,

       

      I'm working on a project that is designed to play nicely with closures (anonymous functions) and it would be really nice if lambda expressions were supported due to the abbreviated syntax.

       

      I posted a question on these forums last year and the reply mentions a "custom asc extension". Is the compiler (even if it's just 4.0) extensable in a way that support for lambda expressions could be added? If it's not *that* extensible, how much effort would be involved?

       

      If it's simply not possible, can I make a language request for the next release?

       

      Cheers,

      Richard

       

      PS. FYI, here are the requirements for a lambda expressions as they would work in the AVM:

       

      "x:int => x + 1" is equivalent to "function (x:int) : int { return x+1; }"

       

      "(x:int) => methodThatReturnsVoid(x)" is equivalent to "function (x:int) : void { methodThatReturnsVoid(x); }"

       

      "() => 5" is equivalent to "function () : int { return 5; }"

       

      "_ => 5" is equivalent to "function (_ : Object) : int { return thereIsAnArgumentButIWontUseIt(); }"

       

      "() =>

      {

          bracesMeansICanUseMultipleStatements();

          return butIHaveToUseReturn();
      }"

       

      is equivalent to

       

      "function():void
      {

          bracesMeansICanUseMultipleStatements();

          return butIHaveToUseReturn();
      }"

       

       

      ... etc

        • 1. Re: Lambda expressions and compiler extensions
          rtalton Level 4

          Doesn't Adobe have a feature request area somewhere for Actionscript? I know it's not here in their help forum.

          I'm using lambdas and anonymous types all the time (.NET/LINQ development) but am still very comfortable with Actionscript 3 as-is. It was never meant to compete feature-for-feature with the likes of C#. Otherwise, I would probably know where the feature request area is located and would be filing enhancement and feature requests every day.

          • 2. Re: Lambda expressions and compiler extensions
            richard.szalay Level 1

            I think you misunderstood my post. I was asking for a pointer in the right direction to implement the support myself, and how the extension would integrate into an existing sdk installation.

             

            I realise that AS3 is not intended to match C# feature-for-feature, but I've been working on a port of Rx and lambda-syntax for anonymous functions would be much more pleasing on the eye.

             

            Besides, if I were set on requesting a feature, it'd be proper generics support!