Skip to content

Instantly share code, notes, and snippets.

@codepreneur
Last active September 14, 2015 07:38
Show Gist options
  • Save codepreneur/087cf4fd10eefdae1784 to your computer and use it in GitHub Desktop.
Save codepreneur/087cf4fd10eefdae1784 to your computer and use it in GitHub Desktop.

Revisions

  1. @ericelliott ericelliott revised this gist May 19, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lambda-not-anon.js
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@
    `)
    })();

    $('#el').on(click, function clickHandler () {
    $('#el').on('click', function clickHandler () {
    console.log(`
    This is an example of a lambda expression that is not anonymous. As you can
    see, it clearly has a name, clickHandler, which can be used inside the
  2. @ericelliott ericelliott revised this gist Apr 19, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lambda-not-anon.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // Anonymous function means "function without a name".

    // This is one of the relatively few cases where the Wikipedia definition of
    // a word, while not entirely wrong, is misleading. Lambdas and Anonymous
    // a word, while not entirely wrong, is misleading. Lambdas and anonymous
    // functions are distinct ideas.

    // These ideas are commonly confused because in many programming languages
  3. @ericelliott ericelliott revised this gist Apr 19, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions lambda-not-anon.js
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,9 @@
    // These ideas are commonly confused because in many programming languages
    // all lambdas are anonymous or vise verse.

    // In JavaScript, not all lambdas are anonymous, and not all anonymous
    // functions are lambdas, so the distinction has some practical meaning.

    (function () {
    console.log(`
    Some people mistakenly think that "lambda" and "anonymous function" have
  4. @ericelliott ericelliott revised this gist Apr 19, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions lambda-not-anon.js
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,9 @@
    // a word, while not entirely wrong, is misleading. Lambdas and Anonymous
    // functions are distinct ideas.

    // These ideas are commonly confused because in many programming languages
    // all lambdas are anonymous or vise verse.

    (function () {
    console.log(`
    Some people mistakenly think that "lambda" and "anonymous function" have
  5. @ericelliott ericelliott revised this gist Apr 19, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions lambda-not-anon.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    // TL;DR - Lambda means "function used as data".
    // Anonymous function means "function without a name".

    // One of the relatively few cases where the Wikipedia definition of a word,
    // while not entirely wrong, is misleading. Lambdas and Anonymous functions
    // are distinct ideas.
    // This is one of the relatively few cases where the Wikipedia definition of
    // a word, while not entirely wrong, is misleading. Lambdas and Anonymous
    // functions are distinct ideas.

    (function () {
    console.log(`
  6. @ericelliott ericelliott revised this gist Apr 19, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lambda-not-anon.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // Anonymous function means "function without a name".

    // One of the relatively few cases where the Wikipedia definition of a word,
    // while not entirely wrong is misleading. Lambdas and Anonymous functions
    // while not entirely wrong, is misleading. Lambdas and Anonymous functions
    // are distinct ideas.

    (function () {
  7. @ericelliott ericelliott revised this gist Apr 19, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions lambda-not-anon.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // TL;DR - Lambda means "function used as data."
    // Anonymous function means "function without a name."
    // TL;DR - Lambda means "function used as data".
    // Anonymous function means "function without a name".

    // One of the relatively few cases where the Wikipedia definition of a word,
    // while not entirely wrong is misleading. Lambdas and Anonymous functions
  8. @ericelliott ericelliott revised this gist Apr 19, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions lambda-not-anon.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    // TL;DR - Lambda means "function used as data."
    // Anonymous function means "function without a name."

    // One of the relatively few cases where the Wikipedia definition of a word,
    // while not entirely wrong is misleading. Lambdas and Anonymous functions
    // are distinct ideas.
  9. @ericelliott ericelliott revised this gist Apr 19, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions lambda-not-anon.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    // One of the relatively few cases where the Wikipedia definition of a word,
    // while not entirely wrong is misleading. Lambdas and Anonymous functions
    // are distinct ideas.

    (function () {
    console.log(`
    Some people mistakenly think that "lambda" and "anonymous function" have
  10. @ericelliott ericelliott created this gist Apr 18, 2015.
    48 changes: 48 additions & 0 deletions lambda-not-anon.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    (function () {
    console.log(`
    Some people mistakenly think that "lambda" and "anonymous function" have
    the same meaning. Let's clear that up.
    In computer science, the most important, defining characteristic of a lambda
    expression is that it is used as data. That is, the function is passed as
    an argument to another function, returned as a value from a function, or
    assigned to variables or data structures.
    This is basically the definition of a first class function. In JavaScript, you
    can use any function as a lambda expression because functions are first class.
    However, that does not mean that all JavaScript functions are therefore lambda
    expressions. For instance, this expression defines a function which gets
    immediately invoked and then dropped on the floor rather than passed,
    exported, or assigned. In other words, the function is not used as data.
    Instead, it's used for a side-effect (logging this text to the console).
    Conceptually, this is more akin to imperative programming than functional
    programming, and thinking of this function as a lambda would add zero useful
    meaning to your understanding of it.
    This distinction is not essential, but is a useful concept when you're
    learning functional programming. In other words, if you understand this
    distinction, you have a deeper understanding of what the word "lambda" means
    in both functional programming and lambda calculus (which are closely
    related).
    It is possible to use functional language features like first-class functions
    in an imperative style, but that adds nothing interesting to your grasp of the
    language, or your grasp of why lambda expressions exist in the first place.
    `)
    })();

    $('#el').on(click, function clickHandler () {
    console.log(`
    This is an example of a lambda expression that is not anonymous. As you can
    see, it clearly has a name, clickHandler, which can be used inside the
    function for the purpose of recursion (also an important concept in functional
    programming).
    It is a lambda expression because of the semantic use -- it's being passed
    to another function as data. The .on() function is using the function as
    an argument -- in other words, communicated as a message (i.e. functions as
    data).
    `);
    });