Go: Redefining For Loop Variable Semantics
The same problem frequently bites me in Python too:<p><pre><code>    functions = []

    for i in range(10):
        functions.append(lambda: print(f&#x27;Hello {i}&#x27;))
    
    for fn in functions:
        fn()

    # Hello 9
    # Hello 9
    # Hello 9
    # Hello 9
    # Hello 9
    # Hello 9
    # Hello 9
    # Hello 9
    # Hello 9
    # Hello 9
</code></pre>
I find it one of Python&#x27;s biggest warts because it&#x27;s silent, hard to troubleshoot (especially the first time!), and like in Go the most straightforward fix looks like a mistake (i=i):<p><pre><code>    for i in range(10):
        functions.append(lambda i=i: print(f&#x27;Hello {i}&#x27;))
</code></pre>
I guess this is a lesson in designing language semantics that match people&#x27;s intuitions, and learning from previous languages&#x27; mistakes.