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

The scope of index variable is different in "for ... in ... range()" and "for ... in ... list()" #509

Closed
yzhang90 opened this issue Nov 25, 2017 · 2 comments

Comments

@yzhang90
Copy link

What's your issue about?

There are two programs:

@public
def foo(x:num): 
    p = 0 
    for i in range(3): 
        p += i
    for i in range(4): 
        p += i
@public
def foo(x:num): 
    p = 0 
    for i in range(3): 
        p += i
    for i in [1, 2, 3, 4]: 
        p += i

The compiler accepts the first program but rejects the second program.

How can it be fixed?

I'm not sure whether this behavior is intended or not. In python, it accepts both program. In my opinion, at least it should both accepts OR both rejects the program OR document this behavior properly.

Cute Animal Picture

image

@fubuloubu
Copy link
Member

@jacqueswww you implemented the i in list feature right? Is i implemented as a variable in the calling scope? It should only exist in the for loop scope (i.e. destroyed after usage)

@jacqueswww
Copy link
Contributor

jacqueswww commented Dec 1, 2017

@DavidKnott can be closed now ;)

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

4 participants