Recursive Lambda Calculus

0

>>> f = lambda b = None, a = 0: a if b is None else lambda c = None: f(c, a + b)

>>>print(f(1)(2)(3)())
6

This recursive lambda function is a solution to a challenge posed to me by a mate on irc.
The function can accept an infinite number of numbers in this weird style, and recursively sum them. Pretty mind boggling and cool if you ask me! Recursive lambdas take some good time to get your head around but you can achieve some weird things with them.

Comments

Your email address will not be published. Required fields are marked *