views:

251

answers:

5

Most programming languages are utilizing lambdas/closures. Which language agnostic source is recommended as the best to learn Lambda basics?

Lambdas/Closures in different languages:

+3  A: 

The Lambda Calculus is language agnostic. The answer depends on what you mean by "basics". The moment you choose any language you've lost your agnostic requirement.

Javascript has closures. I'd add that to the list as well. Java does not - yet.

I think it comes back to where you intend to use them eventually. Go back to Lisp or Scheme, since they're the source, if you want to be old school. Choose Javascript or C# or Python if you will end up using them in a mainstream commercial language.

duffymo
@dyffymo:adde link to javascript closures,link ok? +1
Kb
Java may not have lambda functions but it does have closures. When you anonymously implement an interface, the methods defined have access to the outer variables, just be sure to mark them final.
Juan Mendes
Anonymous inner functions are not the same thing as having closures built in. You can't pass that inner function around and have its outer context still be available.
duffymo
+7  A: 

If you just want something easily digestible, read An Introduction to Lambda Calculus and Scheme. Of course it isn't language-agnostic, but Scheme's implementation is pretty close.

For a deeper understanding, read Types and Programming Languages - Benjamin Pierce. Programming language theory with a thorough study of the lambda calculus. Completely language-agnostic.

danben
@danben: Thank you for the links. +1
Kb
+1 for the link to Pierce. Very nice.
duffymo
+1  A: 

I wouldn't learn them as a "language independent" thing, first. I'd recommend learning them practically, by using them in Javascript first, then broadening to another language (like lisp, C#). Then, if you feel the need to go further, learn the general theoretical stuff.

Cheeso
+3  A: 

I think lambda is simplest in Lisp, since it was designed for that kind of thing, and of the dialects, Scheme tends to be the simplest.

Not coincidentally, the greatest computer science book ever written uses Scheme! Here's SICP's introduction to lambdas.

Ken
+2  A: 

For a beginner wanting to learn the theoretical foundations, danben's suggestion of Pierce's book is unbeatable.

But from the list you give, it sounds like what you want is how to program effectively with first-class function values, which is what lambda evaluates to. You're not going to get this experience, information, or intuition in a language-agnostic package. Worse, in real languages many anonymous functions are created through partial application of Curried functions rather than through explicit lambda; most people use first-class functions heavily find lambdas rather annoying and hard to read.

With that as background, here are two pieces of advice:

  • If you're dead set on learning about lambda, do something with Scheme. Schemers like first-class functions, and Scheme's notation forces more explicit lambdas on the programmer than many other functional languages.

  • As a beginner, you may be better off learning why people want to use these first-class functions to begin with. In that case, read Why Functional Programming Matters by John Hughes. Hughes's paper uses a notation that is somewhat language-agnostic; it is not the notation of any currently popular language, but it is somewhat similar to Caml, F#, Haskell, and ML.

Norman Ramsey