Sunday, March 30, 2014

For a person without a comp-sci background, what is a lambda in the world of Computer Science?
share|edit
add comment

16 Answers

up vote301down voteaccepted
Lambda comes from the Lambda Calculus and refers to anonymous functions in programming.
Why is this cool? It allows you to write quick throw away functions without naming them. It also provides a nice way to write closures. With that power you can do things like this.
Python
def adder(x):
    return lambda y: x + y
add5 = adder(5)
add5(1)
6
JavaScript
var adder = function (x) {
    return function (y) {
        return x + y;
    };
};
add5 = adder(5);
add5(1) == 6
Scheme
(define adder
    (lambda (x)
        (lambda (y)
           (+ x y))))
(define add5
    (adder 5))
(add5 1)
6
Func> adder = 
    (int x) => (int y) => x + y; // `int` declarations optional
Func add5 = adder(5);
var add6 = adder(6); // Using implicit typing
Debug.Assert(add5(1) == 6);
Debug.Assert(add6(-1) == 5);

// Closure example
int yEnclosed = 1;
Func addWithClosure = 
    (x) => x + yEnclosed;
Debug.Assert(addWithClosure(2) == 3);
As you can see from the snippet of Python and JavaScript, the function adder takes in an argument x, and returns an anonymous function, or lambda, that takes another argument y. That anonymous function allows you to create functions from functions. This is a simple example, but it should convey the power lambdas and closures have.
share|edit
22 
This is by by far the best yet simplest description of lambda I have ever seen. Yet you managed to not lose any of the key ideas bravo. +1 –  faceless1_14 Aug 10 '09 at 13:36
   
Agreed. I have seen the light! Thanks. =) –  Chris Cooper Apr 14 '10 at 23:53
   
+1 Best explanation I've seen. Thanks –  Rich Jul 20 '10 at 11:05
   
awesome, thanks much –  Orbit Oct 29 '10 at 13:38
3 
What a superb explanation!! I have the power now. –  trusktr Feb 15 '11 at 3:50
show 1 more comment

6 comments:

Anna said...

Great and Useful Article.

Online Java Training

Online Java Course

Java EE course

Java Course in Chennai

Java Training in Chennai

Java Training Institutes in Chennai

Java Interview Questions

Java Interview Questions

oakleyses said...

jordan pas cher, chanel handbags, nike outlet, michael kors pas cher, kate spade outlet, replica watches, longchamp pas cher, nike free, jordan shoes, christian louboutin shoes, nike free run, louis vuitton outlet, oakley sunglasses, ray ban sunglasses, polo ralph lauren, ugg boots, christian louboutin uk, air max, louis vuitton outlet, ugg boots, tiffany jewelry, polo ralph lauren outlet online, burberry pas cher, prada outlet, nike air max, gucci handbags, sac longchamp pas cher, ray ban sunglasses, louboutin pas cher, louis vuitton, uggs on sale, tiffany and co, oakley sunglasses, louis vuitton outlet, ray ban sunglasses, longchamp outlet, louis vuitton, longchamp outlet, replica watches, nike roshe, polo outlet, oakley sunglasses, cheap oakley sunglasses, oakley sunglasses wholesale, christian louboutin, christian louboutin outlet, tory burch outlet

oakleyses said...

lululemon canada, nike air max, burberry outlet, oakley pas cher, burberry handbags, coach outlet store online, kate spade, michael kors outlet, michael kors, nike air force, true religion jeans, true religion outlet, michael kors, polo lacoste, nike tn, new balance, abercrombie and fitch uk, michael kors outlet, uggs outlet, michael kors outlet, ralph lauren uk, michael kors outlet online, replica handbags, coach outlet, true religion outlet, coach purses, nike free uk, sac vanessa bruno, mulberry uk, michael kors outlet online, michael kors outlet online, michael kors outlet online, north face, uggs outlet, converse pas cher, hogan outlet, nike air max uk, hollister pas cher, sac hermes, nike roshe run uk, hollister uk, nike air max uk, true religion outlet, timberland pas cher, vans pas cher, ray ban pas cher, guess pas cher, ray ban uk

preetha S said...

Great Knowledge and hardwork. Thanks for helping
spring interview questions and answers for experienced
salesforce interview questions
bootstrap interview questions

Penyebab Mual dan Muntah Tiba-tiba said...

Thank you for sharing an interesting and very useful article. And let me share an article about health here I believe this is useful. Thank you :)

Cara Menghilangkan Benjolan di Langit Mulut
Cara Menghilangkan ambeien/Wasir Secara Permanen
Obat Asma Alami (untuk semua usia),Terbukti Ampuh
Obat Diabetes Herbal, Pengobatan Alami Diabetes
Obat Penghancur Kista, Pengobatan Kista Tanpa Operasi
Cara Mengobati Konjungtivitis Secara Alami

deraz said...

النجم
كهربائي منازل وفلل فى دبي
كهربائي منازل بدبى