V version: 0.1.20 c8a781b
OS: Win 10 1809
What did you do?
infinite loop REPL
What did you expect to see?
>>> for{}
(stuck here)
What did you see instead?
>>> for{}
C:\Program Files\v\.vrepl_temp.v:2:11: unexpected token: `for`
I believe that you can't use control flow statements in REPL
Expressions and printing is only available right now.
I believe that you can't use control flow statements in REPL
Expressions and printing is only available right now.
however, following infinite loop is working fine in REPL:
>>> mut miao:=1
>>> for{miao=2}
Oh yeah! It seems like for ever loop doesn't works with REPL only.
In addition:
for {continue} works (infinitelly)
for {a:=1} works (infinitelly)
for {1==1}
/v/.vrepl_temp.v:2:9: unexpected token: ==
shouldn't for {a:=1} result in a redefinition error?
@wh-timme It wouldn't because it is just reinitialising every iteration?
a:=1
a:=1
print(a)
code like this would be a redefinition error in v run
the only issue with
a := 1
a := 1
vs
for{a:=1}
The first set is within the same scope, while the a in the for loop is technically in a new scope with each iteration. I don't think the for loop should fail, but the double a:=1 should. At least from my understanding of v's scoping.
for{continue}
gives this error, and is right:
.vrepl_temp.v:2:11: unexpected token: for
I quote @adlesh, i think that for i, v in list {//some code} probably consists on a scope (we can name it A which runs multiple "closures" inside, so only i and v (or external variables) are shared into the scope A. I think it's wanted (concurrency..?).
For loops works, but you have to add a space : for {}.
It is because of the way the REPL tries to print things (It searches if there is no spaces, colons, equals or commas).
When you give for{}, it doesn't trigger any of those and tries to print, thus resulting in a println(for{}) giving the error. This needs to be worked on and is the problem behind many of the REPL related issues.
Most helpful comment
shouldn't
for {a:=1}result in a redefinition error?