[Python] Seeking for help illustrate this Y-combinator Python implementation

Discussão em 'Python' iniciado por Stack, Maio 23, 2025.

  1. Stack

    Stack Membro Participativo

    I once read this Python implementation of Y-combinator in a legacy code deposit:

    def Y_combinator(f):
    return (lambda x: f(lambda *args: x(x)(*args)))(
    lambda x: f(lambda *args: x(x)(*args))
    )


    And there exists an example usage:

    factorial = Y_combinator(
    lambda f: lambda n: 1 if n == 0 else n * f(n - 1)
    )


    Could anyone be so kind to teach how should I read the code to interpret it? I am totally lost in trying to connect those lambdas altogether...

    Continue reading...

Compartilhe esta Página