In programming (especially in functional languages), a lambda function (also anonymous function) is a user-defined function without an identifier (i.e., nameless). They’re useful mainly to be passed to higher-order functions or to construct the result of a higher-order function.
Mathematically speaking, lambda functions mainly come from the idea of lambda calculus, where all functions are anonymous.
Language-specific
In Python
In Python, we can declare lambda functions as follows:
lambda x: # expression goes here
lambda y: idx[y] # for example
In C++
Since C++11, we can construct lambdas with:
auto f = [](auto param1, auto param2) {
return param1 + param2;
}
In functional programming, a closure is a function-like entity that can capture variables from the surrounding environment. Unlike regular functions, they’re able to access and modify variables from the enclosing scope.
Basically lambda functions.