I haven’t really been able to get a firm grasp on creating and using lambda expressions. I know how to use them in linq statements, but I really don’t understand what’s going on behind the scenes. I also havent been able to find a complete tutorial on when to use them, how to define them, etc.
Second part…
They say that Javascript is a LAMBDA language, I know javascript fairly well, just wondering what types of concepts that apply to javascript lambdas and c# lambdas.
thrid part…
what is the difference between a functional language and an lambda language?
Any suggestions?
Let me give you the scoop on what’s going on behind the scenes. It is more straightforward than you think.
Suppose you have:
All the compiler does is pretends that you wrote:
That’s all there is to it. A lambda is just a compact syntax for writing “hoist all the outer local variables used by the lambda into a class, make a method on the class with a given body, and make me a delegate out of that method”.
Function closures in JScript work essentially the same way. JScript of course is not a class-based language so the details are slightly different, but the idea is the same. In C#, the newly created delegate object keeps track of the locals class, which has the variable state. In JScript, the newly created function object has a reference to the activation frame of the function which created the closure, which is basically the same information.
The way lambdas are converted to expression trees is rather different, but this should at least get you started in understanding the idea of lambdas.