32 comments

[ 2.6 ms ] story [ 71.2 ms ] thread
A question about the klipse plugin: Does code inside it have access to DOM elements just as javascript running on the console would? Would be a fantastic addition that could really make developing an interactive coding exercise for kids learning about the web a breeze!
If I'm not mistaken, this isn't the full Y combinator yet. It's a partial step towards deriving the full Y combinator.

    (f => (x => x(x))(y => f(x => y(y)(x))))
    (func => n => (n === 0) ? 1 : (n * func(n - 1)))
    (19)
Notice that the ugly func(func)(n-1) recursive call with the proper Y combinator simply became func(n-1).

The full Y combinator is also vastly more mystical and less obvious than the partial step :)

> The full Y combinator is also vastly more mystical and less obvious than the partial step :)

The full Y conbinator simply binds func to func(func) as seen in `(y => f(x => y(y)(x))))`, an easy jump to make and pretty easy to understand.

For what purpose?
Quoth xkcd, "Tail recusion is its own reward."

In all seriousness, even if the y combinator is practically useless in languages that don't have proper TCO (which is specced for ES7), it's a useful learning tool, is powerfully mind expanding, and can help to demonstrate the power of the λ-calculus.

Is the Y-combinator any more or less dependent on TCO than regular recursion?

The Y combinator is useless in languages that already have builtin support for recursive functions.

No, Y is handy for defining nameless recursive functions, but it blows the stack even faster if you don't have TCO.
Obligatory 'To Dissect a Mockingbird' link:

http://dkeenan.com/Lambda/index.htm

If you have never read this before, then I highly recommend it. It's a beautiful way to picture combinators.

Indeed. It's by far best explanation of the concept that I've seen, and it, along with some of Matt Might's posts, helped me gain a deeper appreciation for concepts like Church Encoding, and λ-calculus in general.
The code samples fail in Safari. The first one prints "SyntaxError: Unexpected token '>'".
You need Safari Technology Preview for ES6 support.
Your version of Safari most likely lacks support for ES6 features like arrow functions[0], you could use babel[1] to transpile the code to ES5:

  (function (f) {
    return f(f);
  })(function (func) {
    return function (n) {
      return n === 0 ? 1 : n * func(func)(n - 1);
    };
  })(19);

[0] http://caniuse.com/#feat=arrow-functions

[1] https://babeljs.io/repl/

I find the Python implementation is slightly more elegant:

    (lambda f: f(f))
    (lambda fn: lambda n: 1 if n == 0 else (n * fn(fn)(n - 1)))
    (5)
Yeah. But I didn't find a way to run python code in the browser. Currently in Klipse, we support javascript, ruby, clojure and php...
I did not know there was a Ruby to JS compiler. That's __really__ fascinating! Do you have plans to support Python any time soon?
I'd love to support python.

If you find a way to evaluate python code in the browser, please let me know: viebel@gmail.com

To be fair, the article would be more aptly titled "Recursion without function names". In any recursion you need a way to reference the original function somehow. They're using a function parameter to accomplish that via indirection.
There are no names except function arguments.

No 'x=...'

Please reread my post. The function parameter is the name.
Do you know a language without argument names?
You're missing the point. Nevermind.
Kitten -> meet laser pointer

Nerd -> meet article