News for hackers. Stuff that matters.
Re:Python’s lambda is broken by enum on Thursday April 09, 2009 @01:11PM (#554710)
Lambda is fine. The loops are mutating the variable i, so all the lambda share the same i. Apparently, list comprehensions also use mutation--I suppose that's fine.
Re:Python’s lambda is broken by scott_s on Thursday April 09, 2009 @02:24PM (#554865)
Indeed, Python is using lexical scoping. This behavior is well known.
Re:Python’s lambda is broken by jrockway on Thursday April 09, 2009 @02:29PM (#554880)
While true, that is not really the issue. The issue is which lexical scope the loop iterator is defined in. In python, it is apparently like this:

    i = 0
    increment i
    <do loop body with i>
It could have been:

    i = 0
    increment 1
      create new environment
      bind i here
      <do loop body>
In the second case, each loop body would have its own "i". In the first case, they all share the same "i".