BuK/IIm20/Vorlesung 9 Lemke

Aus ProgrammingWiki

Wiki-Quelltext dieser Seite.

<language>Python</language>
== Übungsaufgabe S. 5 ==

=== Implementation der angegebenen Lambdafunktionen in Python ===

'''(λx. x)'''

<code id="60aa825353519">
identity_function = lambda x : x
</code>

'''(λf . (λx. (f x) ) )'''

Als Python-Lambdafunktion:

<code id="60aa825353582">
application = lambda f : lambda x : f(x)
</code>
<run id="60aa825353648">
test_f = lambda x : x * 3
applied = application(test_f)
print(applied(4))
</run>

Als reguläre Pythonfunktion:

<code id="60aa8253535e9">
def outer(f):
	def inner(x):
		return f(x)
	return inner
</code>
<run id="60aa825353697">
def test_f(x):
	return x * 3

applied = outer(test_f)
print(applied(4))
</run>