The difference between a function and a lambda

functional programminglambdamethods

I'm a little bit confused about 'function' and 'lambda'. I've seen some examples showing that the scheme keyword lambda works very similarly to the JavaScript keyword function, but I really don't know how they are related.

I'm told that 'function' and 'method' can be used interchangeably when speaking about objects in .net. I'm wondering if 'lambda' and 'function' similarly mean the same thing. I wonder if 'lambda' has some esoteric meaning, seeing that the Greek letter lambda (λ) appears in so many avatars on this site. To make things even more confusing, in .net, the functional parts of C# refer to function expressions passed to another function as 'lambda expressions', so the word really seems to be all over the place.

I'm also vaguely familiar with the term 'lambda calculus'.

What is the difference between a function and a lambda?

Best Answer

The word "lambda" or "lambda expressions" most often refers to anonymous functions. So in that sense a lambda is a kind of function, but not every function is a lambda (i.e. named functions aren't usually referred to as lambdas). Depending on the language, anonymous functions are often implemented differently than named functions (particularly in languages where anonymous functions are closures and named functions are not), so referring to them with different terms can make sense.

The difference between scheme's lambda keyword and Javascript's function keyword is that the latter can be used to create both anonymous functions and named functions while the former only creates anonymous functions (and you'd use define to create named functions).

The lambda calculus is a minimal programming language/mathematical model of computation, which uses functions as its only "data structure". In the lamdba calculus the lambda-symbol is used to create (anonymous) functions. This is where the usage of the term "lambda" in other languages comes from.