Skip to content

Instantly share code, notes, and snippets.

@tscholak
Created August 29, 2018 23:43
Show Gist options
  • Save tscholak/fa9953810456429458db769d9031c53c to your computer and use it in GitHub Desktop.
Save tscholak/fa9953810456429458db769d9031c53c to your computer and use it in GitHub Desktop.

First some boilerplate:

def side_effecty_id(x):
        print(x)
        return x

Now, consider:

lambdas_0 = tuple((lambda x: x >= side_effecty_id(i)) for i in range(10))
tuple(l(5) for l in lambdas_0)

Curiously, this gives

9
9
9
9
9
9
9
9
9
9
(False, False, False, False, False, False, False, False, False, False)

while

lambdas_1 = tuple((lambda i: lambda x: x >= side_effecty_id(i))(i) for i in range(10))
tuple(l(5) for l in lambdas_1)

gives

0
1
2
3
4
5
6
7
8
9
(True, True, True, True, True, True, False, False, False, False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment