Anonymous functions have been a feature of programming languages since Lisp in 1958, and a growing number of modern programming languages support anonymous functions.
Short/simple anonymous functions used in expressions may be easier to read and understand than separately defined named functions, though without a descriptive name they may be more difficult to understand.
Consider this Python code sorting a list of strings by length of the string: The anonymous function in this example is the lambda expression: The anonymous function accepts one argument, x, and returns the length of its argument, which is then used by the sort() method as the criteria for sorting.
This is commonly used to customize the behavior of a generically defined function, often a looping construct or recursion scheme.
The above form is discouraged by the creators of the language, who maintain that the form presented below has the same meaning and is more aligned with the philosophy of the language: The filter function returns all elements from a list that evaluate True when passed to a certain function.
The same as with map, the form below is considered more appropriate: A fold function runs over all elements in a structure (for lists usually left-to-right, a "left fold", called reduce in Python), accumulating a value as it goes.
This can be used to combine all elements of a structure into one value, for example: This performs The anonymous function here is the multiplication of the two arguments.
In filter, the value that is accumulated is a new list containing only those elements that match the given condition.
The following is a list of programming languages that support unnamed anonymous functions fully, or partly as some variant, or not at all.
For example, the ML languages are statically typed and fundamentally include anonymous functions, and Delphi, a dialect of Object Pascal, has been extended to support anonymous functions, as has C++ (by the C++11 standard).