I've been reading up on some functional programming literature and am a bit confused by the proliferation of terminology for "first class functions".
1) I understand that the big difference between Java's anonymous function with closures is that the former cannot access free variables. Anonymous functions can be passed into methods as well as returned as return values.
2) python has a construct called lambdas. I've never programmed in python; thus I would like to know if they just another name for closures.
I'm no expert (just trying to learn the functional paradigm too), as far as I know, lambda is the name for anonymous functions (should be equivalent to lambda functions too). Java doesn't have anonymous functions, they're simulated through anonymous classes. (there's a huge debate on adding them, because they're needed for closures) A closure is a little different, for what I could understand from the wikipedia article, is the combination of the anonymous function with the other variables referenced by it.
Gabriel is correct. A lambda expression by itself is not a closure. A closure is a construct that binds a lambda expression to an evaluation context (lexical or dynamic)used to lookup any free variables (functional or not) in the lambda body. Passing around closures thus allows evaluation of a lambda expression to be done in the environment where the closure was created as opposed to the environment where the closure is evaluated.
As an example: if you have two separate evaluation stacks A and B and you create a closure in one of the stacks (say A) and pass it as an object to a function that is executing in the other stack (say B), then evaluation in stack B of the lambda expression in the closure that was created in stack A will be done in the environment context in stack A where the closure was created. Therefore the name closure. It closes the evaluation environment of the associated lambda to be the environment where the closure is created, regardless of where the closure is evaluated.
As you see, this mechanism is very powerful for creating complex control structures and evaluation regimes.
Originally posted by Jorge Phillips: [QB]if you have two separate evaluation stacks A and B and you create a closure in one of the stacks (say A) and pass it as an object to a function that is executing in the other stack (say B), then evaluation in stack B of the lambda expression in the closure that was created in stack A will be done in the environment context in stack A where the closure was created.[QB]
I was lost for some time there, but finally got it. Thanks