Hacker News new | ask | show | jobs
by samratjp 5651 days ago
In the past, I would've said read The Little Schemer book for better understanding recursion and lambda (basically, a lambda function is an anonymous function - meaning you don't have to name it). JavaScript is actually a great language to better understand functional programming - it really is Scheme in C-like syntax. Here's a great little chapter on functional programming in javascript (http://eloquentjavascript.net/chapter6.html). Just bear with me and read it - it's extremely worth the trouble. You'll understand the syntax fine even if you don't know javascript.

After you read that, hopefully you'll start passing around functions as arguments inside another functions. It's tremendously fun and changes your way of thinking about code.

And this little answer in StackOverFlow summarizes what lambdas can do and how you can use it in python: http://stackoverflow.com/questions/890128/python-lambda-why/...

The simplest explanation is think of your program functions like mathematical functions that spit out values, with that in mind you can start sending in functions as arguments. A very brief e.g from the link:

def addition(n): return lambda x: x + n f = addition(3) f(4) # is 7

here, f is actually binded to a function - the addition function from above (because it returned a function called lambda).

1 comments

You seem to be conflating the idea of closures and functional programming. Functional programming is more about avoiding state and side-effects, which is antithetical to most Python and JavaScript code. A lot of languages, including C, support the kind of programming you're describing, but that's not "functional" per se.

http://en.wikipedia.org/wiki/Functional_programming