Can we fix this?
deadalnix
deadalnix at gmail.com
Thu Sep 30 11:00:15 UTC 2021
On Thursday, 30 September 2021 at 02:50:13 UTC, jfondren wrote:
> On Thursday, 30 September 2021 at 02:25:53 UTC, jfondren wrote:
>> In basically every language that exists the expected behavior
>> from this code is 3 4 5.
>
> Exceptions: Python, Nim, Rust, probably C++, probably Zig.
>
> In order:
>
> ```python
> funcs = []
>
> for i in range(0, 3):
> n = i + 2
> funcs.append(lambda: print(n))
>
> for f in funcs:
> f() # output: 4 4 4
> ```
>
No, in python, variable are not scoped. The semantic is
consistent.
You'll note that it generally doesn't matter in python, because
there is no notion of immutability or construction/destruction,
so both behaviors are acceptable for python.
D either needs to ditch constructor, destruction, immutable, and
anything that has to do with lifetime.
More information about the Digitalmars-d
mailing list