3 ms·
The same can be done with Python lambdas: >>> ZERO = lambda f: lambda x: x >>> FIVE = lambda f: lambda x: f(f(f(f(f(x))))) >>> to_int = lambda f: f(lambd
by i2 15y ago
The same can be done with Python lambdas:
>>> ZERO = lambda f: lambda x: x
>>> FIVE = lambda f: lambda x: f(f(f(f(f(x)))))
>>> to_int = lambda f: f(lambda x: x+1)(0)
... etc.
- freyrs3 15y agoYeah you can do the full lambda calculus in Python: https://raw.github.com/sdiehl/church-numbers/master/church.py https://raw.github.com/sdiehl/church-numbers/master/church.p...
- neilk 15y agoMark-Jason Dominus did this for Perl, more than a decade ago. http://perl.plover.com/lambda/ http://perl.plover.com/lambda/ aka "How to write a 163 line program to compute 1+1" Although I really like the OP's approach since he slowly morphs a program his readers can understand, rather than constructing a programming system from scratch.