Live data from Hacker News

Recursions without names: Introduction to the Y combinator in JavaScript

blog.klipse.tech

1–10 of 33 posts

Re: Recursions without names: Introduction to the Y combinator in JavaScript

#2
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!

Re: Recursions without names: Introduction to the Y combinator in JavaScript

#3
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 :)

Re: Recursions without names: Introduction to the Y combinator in JavaScript

#6
post #4

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.

Re: Recursions without names: Introduction to the Y combinator in JavaScript

#7
post #5

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.

Re: Recursions without names: Introduction to the Y combinator in JavaScript

#8

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.

Re: Recursions without names: Introduction to the Y combinator in JavaScript

#10

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!

Indeed, the klipse plugin has access to DOM elements.

What ideas do you have for kids?

I have tried to do something for kids here: kids.klipse.tech

The klipse plugin concept is explained in details:

1. http://blog.klipse.tech/javascript/2016/06/20/blog-javascrip...

2. https://github.com/viebel/klipse

Post reply on HN