Jump to content

Lambda (programming)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Norgren (talk | contribs) at 19:45, 28 March 2011. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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

Examples

An example of this use of lambda in the Python language is this section of computer code that sorts a list alphabetically by the last character of each entry:

>>> stuff = ['woman', 'man', 'horse', 'boat', 'plane', 'dog']
>>> sorted(stuff, key=lambda word: word[-1])
['horse', 'plane', 'dog', 'woman', 'man', 'boat']


In C#, lambda expressions are often used with LINQ:

var allWikipediaPages = GetAllWikipediaPages();
var lambdaWikipediaPage = allWikipediaPages.First(wp => wp.Title == "Lambda (programming)");