views:

1686

answers:

7
+22  Q: 

What is a Lambda?

Could someone provide a good description of what a Lambda is? We have a tag for them and they're on the secrets of C# question, but I have yet to find a good definition and explanation of what they are in the first place.

+5  A: 

How about Wikipedia's lambda calculus article for a start?

Then Wikipedia's functional programming article as a followup.

Thorsten79
+1  A: 

Clipped from wikipedia: http://en.wikipedia.org/wiki/Lambda#Lambda.2C_the_word

In programming languages such as Lisp and Python, lambda is an operator used to denote anonymous functions or closures, following lambda calculus usage.

Adrian
I guess you meant this line: In programming languages such as Lisp and Python, lambda is an operator used to denote anonymous functions or closures, following lambda calculus usage.I'd already scanned the article but missed that.
Fred
+5  A: 

It's just an anonymous function declared inline, most typically assigned to a delegate when you don't want to write a full-fledged function.

In languages like lisp/scheme, they're often passed around quite liberally as function parameters, but the idiom in C# typically finds lambdas used only for lazy evaluation of functions, as in linq, or for making event-handling code a bit terser.

JasonTrue
+12  A: 

"Lambda" refers to the Lambda Calculus or to a specific lambda expression. Lambda calculus is basically a branch of logic and mathematics that deals with functions, and is the basis of functional programming languages.

~ William Riley-Land

SoloBold
+16  A: 

Also called closures or anonymous functions.. I found the best description here. Basically, inline block of code that can be passed as an argument to a function.

Gulzar
+3  A: 

There's not really such a thing as 'a lambda' in programming. It depends on the language, etc.

In short, normally a language that 'has lambdas' uses the term for anonymous functions or, in some cases, closures. Like so, in Ruby:

f = lambda { return "this is a function with no name" }
puts f.call
thenduks
+36  A: 

Closures, lambdas, and anonymous functions are not necessarily the same thing.

An anonymous function is any function that doesn't have (or, at least, need) its own name.

A closure is a function that can access variables that were in its lexical scope when it was declared, even after they have fallen out of scope. Anonymous functions do not necessarily have to be closures, but they are in most languages and become rather less useful when they aren't.

A lambda is.. not quite so well defined as far as computer science goes. A lot of languages don't even use the term; instead they will just call them closures or anon functions or invent their own terminology. In LISP, a lambda is just an anonymous function. In Python, a lambda is an anonymous function specifically limited to a single expression; anything more, and you need a named function. Lambdas are closures in both languages.

Eevee
the term might be intended to imply lambda calculus http://en.wikipedia.org/wiki/Lambda_calculus
Steven A. Lowe