Skip to content

Instantly share code, notes, and snippets.

@JustinStitt
Last active April 3, 2023 06:10
Show Gist options
  • Save JustinStitt/5ff67c6c738febe66455383dee093f76 to your computer and use it in GitHub Desktop.
Save JustinStitt/5ff67c6c738febe66455383dee093f76 to your computer and use it in GitHub Desktop.

Consider the following Python code:

a = 7
g = lambda x: a * x
a = 2
g(10)
  1. What is the result of evaluating the Python code?

20

  1. Convert the code to an expression in the Lambda Calculus
$$(\lambda a . (\lambda g . (\lambda x . a * x)g)10)2$$
  1. Write an equivalent Python expression using the lambda keyword
g = lambda a: lambda x: lambda: a * x
g(10)(2)()
  1. What is the result of evaluating the Python expression?
In[0] : g(10)(2)()
Out[0]: 20
  1. What accounts for the difference between (1) and (4)?
Both results are 20.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment