kuroko-lang / kuroko

Dialect of Python with explicit variable declaration and block scoping, with a lightweight and easy-to-embed bytecode compiler and interpreter.
https://kuroko-lang.github.io/
MIT License
427 stars 25 forks source link

[KEP] Allow using `let` to define local variable in "legacy `for` loop" like Javascript #34

Closed anzhi0708 closed 1 year ago

anzhi0708 commented 1 year ago

I can't find suitable title... so I'll go with 'KEP' (Kuroko Enhancement Proposal) lol

Using var defines global and let defines local variable in nodeJS (for loop) IMG_20221020_105504 They act differently.

Well, just personal thoughts though ;-)

anzhi0708 commented 1 year ago

Before:

for _ in range(5):
    let i = _       # catch the value
    ...             # do stuff

After:

for let i = 0; i < 5; i++:  # init local variable i
    ...  # do stuff

...or even...

for let i in range(5):
    ...
klange commented 1 year ago

I don't want to use issues for enhancement proposals, so I've turned on Discussions - one of the default categories is "Ideas", let's put this sort of thing there.

(Also I really have to resist the urge to come up with an alternative to "proposal" that starts with "k" so we can have "KEKs"... good thing I can't find a sensible one...)