Maybe somebody could explain what the difference between a lambda, a closure and a monad is, and how/if they are different from a function pointer (or generalization of it like a signal), or from unary or binary function objects. (my C++ bias in asking this question may be obvious ;) ) I see the first three concepts used interchangeably (as far as I understand), but maybe that's because they're used slightly differen…
I see several explanations here already, none of which gets at the essence of the difference between a lambda expression and a closure. A lambda expression (or juat "lambda" for short) is a syntactic construct: something you write in your program, like "(lambda (x) (+ x 1))" or "function (x) { return x + 1; }". Lambda expressions, like any other evaluable expressions, have values . Just as the expression "2 + 2" has…
What's a Closure?
31–40 of 60 posts
Re: What's a Closure?
#32This was a clever use of unit tests to help you "pass" each lesson. I've read a bunch of tutorials on closures, but this one really helped me "get" it. Sure, it takes liberties and glosses over things... but seeing it grow right before my eyes was really helpful.
Re: What's a Closure?
#33Re: What's a Closure?
#34Re: What's a Closure?
#35Re: What's a Closure?
#36Wow, I love the flow! Except JSLint. JSLint barfs all over otherwise valid JavaScript and provides really unhelpful error messages. For a minute, I thought that I forgot how to write valid JavaScript.... Hate! Hate! Hate! You're teaching folks to program, not write syntactically pure JS. But drop that and the experience is great.
(Creator here) Ha, yeah JSLint really provokes strong emotions. Before I added in JSLint, if you misplaced one semicolon or forgot a parentheses, none of the tests would run and it would just say "program failed". That was incredibly frustrating to me. I figured that if I was getting frustrated, and I was the creator of the tests, then random users would be REALLY frustrated. So I added in JSLint. Now you get line an…
Re: What's a Closure?
#37fC(gC(function(){success,failure};),failure);
but the desired answer checked gC even if fC already failed..
Re: What's a Closure?
#38Maybe somebody could explain what the difference between a lambda, a closure and a monad is, and how/if they are different from a function pointer (or generalization of it like a signal), or from unary or binary function objects. (my C++ bias in asking this question may be obvious ;) ) I see the first three concepts used interchangeably (as far as I understand), but maybe that's because they're used slightly differen…
I see several explanations here already, none of which gets at the essence of the difference between a lambda expression and a closure. A lambda expression (or juat "lambda" for short) is a syntactic construct: something you write in your program, like "(lambda (x) (+ x 1))" or "function (x) { return x + 1; }". Lambda expressions, like any other evaluable expressions, have values . Just as the expression "2 + 2" has…
A closure is an open function paired with an environment that maps the unbound variables to values. The pairing is called a closed function, or the closure of an open function.
Re: What's a Closure?
#39Maybe somebody could explain what the difference between a lambda, a closure and a monad is, and how/if they are different from a function pointer (or generalization of it like a signal), or from unary or binary function objects. (my C++ bias in asking this question may be obvious ;) ) I see the first three concepts used interchangeably (as far as I understand), but maybe that's because they're used slightly differen…
I see the first three concepts used interchangeably (as far as I understand)... Either you misunderstood, or the people using them misunderstood. Lambdas are anonymous functions. In javascript terminology: _.map(someNumbers, function (x) { return x +1; } /* Closures are a way of hiding state (or at least data) in anonymous functions: makeCounter() { var x = 0; function numCalls() { return x++; }; Monads are a method…
var c = 2;
var f = function (x) { return (2 * x); };
var g = function (h, x) { return h(x); };Re: What's a Closure?
#40Anyone else try to do a lazy AND evaluation for chapter 12 and have it fail? I did fC(gC(function(){success,failure};),failure); but the desired answer checked gC even if fC already failed..
> Your function bothC should call both fC and gC no matter what
What happens in your code if fC fails?