Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Late-binding" isn't the issue with closures on a loop #1030

Open
SoniEx2 opened this issue Jan 13, 2020 · 0 comments
Open

"Late-binding" isn't the issue with closures on a loop #1030

SoniEx2 opened this issue Jan 13, 2020 · 0 comments

Comments

@SoniEx2
Copy link

SoniEx2 commented Jan 13, 2020

Lua also has late-binding closures, as can be seen here: https://repl.it/repls/HotpinkEagerQuery (the first one intentionally misused to highlight the difference between block scope and function scope)

It just also has block scope. That's the thing python doesn't have, thus causing the confusion.

Block scope is better emulated with nested functions, such as:

for i in range(5):
  def block_scope_emulation(i):
    def thing(x):
      return x*i
  block_scope_emulation(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant