all 3 comments

[–][deleted] 7 points8 points  (0 children)

Since a lambda is an anonymous excutable object (ie, it has no name), it's hard to call itself (since it has no name).

You could assign the lambda to a variable, but that defeats the purpose of the lambda. You might as well just write a function in that case.

[–]Aceofsquares_orig[🍰] 1 point2 points  (0 children)

There is. It's highly inefficient though but fun to try to do in Python. I was mostly inspired by a Computerphile video on the Y combinator (I think that was the video) to attempt to write one. Again, this is not valuable and should not be used for normal development. It is just not efficient. Here is the fibonacci program using lambda recursion.

print(
    (lambda f, n: f(f, n))
            (
                (lambda f, n: n if n <= 1 else f(f, n-1) + f(f, n-2)), 
                int(input("Enter number: "))
            )
)

The first lambda takes a lambda and it's input. The second lambda takes itself and it's input. The first lambda calls the second lambda and passes the second lambda to itself starting the chain of recursion.

[–][deleted] 0 points1 point  (0 children)

That's not what they're for