Usefulness of the "not in" operator

Nobody nobody at nowhere.com
Mon Oct 10 13:29:49 EDT 2011


On 2011年10月09日 02:25:27 +0200, Alexander Kapps wrote:
> Even if it's off-topic, could you add some similar explanations for 
> Church numerals (maybe Lambda calculus it isn't too much?)

The Church numeral for N is a function of two arguments which applies its
first argument N times to its second, i.e. (f^N)(x) = f(f(...(f(x))...)).
IOW:
def zero(f, x):
 return x
def one(f, x):
 return f(x)
def two(f, x):
 return f(f(x))
def three(f, x):
 return f(f(f(x)))
And so on.
In general:
def applyN(n, f, x):
 for i in xrange(n):
 x = f(x)
 return x
def church(n):
 return lambda f, x: applyN(n, f, x)
seven = church(7)	# this is the Church numeral for 7
> seven(lambda x: x + 1, 0)
7
> seven(lambda x: x * 2, 1)
128
> seven(lambda x: x + ".", "")
'.......'


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /