Skip to content

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

Open
@SoniEx2

Description

@SoniEx2

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions