News for hackers. Stuff that matters.
Re:Adventures of an imperative programmer in the land of fp by ww520 on Friday August 27, 2010 @01:37PM (#1639479)
Javascript's treatment of anonymous function is the easiest to understand for imperative background since it uses the same syntax as a named function.

Defining an anonymous function:

    function(a, b) {
        return a+b;
    }
Giving an anonymous function a name (or assigning to a variable):

    var add = function(a, b) {
        return a+b;
    }
Defining a function with a name (just a shorthand of the above):

    function add(a, b) {
        return a+b;
    }
This makes it clear that the object stored in 'add' is a function object and can be passed around like other objects. That's the essence of the 'function as a first class object' concept.

If you have the time, I highly recommend watching the SICP video. It very gently introduces most of the FP concepts and many others. It's a classic. http://freevideolectures.com/Course/2378/Structure-and-Inter...

Re:Adventures of an imperative programmer in the land of fp by kanak on Sunday August 29, 2010 @11:37PM (#1645306)
Wow that's almost the same as scheme. Here's the scheme version of the above code:

Your example would be translated as:

(lambda (a b) (+ a b)) ;; making an anonymous function

(define add (lambda (a b) (+ a b))); ;; calling the anonymous function "add"

(define (add a b) (+ a b)) ;; syntactic sugar for above.