What is a Lambda?

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.

Leave a Comment