You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
For loop should be implemented for strings without declaration #1475
Related to #206 which was closed couple of days ago.
a :str
for a in "abc":
print (a)
(lp) C:\Users\kunni\lpython>python try.py
a
b
c
(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
semantic error: Only function call `range(..)` supported as for loop iteration for now
--> try.py:3:5 - 4:17
|
3 | for a in "abc":
| ^^^^^^^^^^^^^^^...
...
|
4 | print (a)
| ...^^^^^^^^^^^^^^^^^
Considering range is the only supported function, a string input is not another function like reverse(str_name) or enumerate(str_name) so a better error message can be provided if this is not in the implementation plan as of now.
I've been trying to address this issue , but not sure what approach could be used for the same . Let's say we want to address
i: i32
for i in [1, 2, 3]:
print(i)
Here the iterable we have is of type AST::List_t and we currently can't address this case but we can address cases where the list has been assigned to a variable .
i: i32
lst: list[i32] = [1, 2, 3]
for i in list:
print(i)
Here the iterable is of type AST::Name_t . So what comes to my mind for addressing the first case is ... that why don't we assign a dummy name to the list and create an object of AST::Name_t type and repeat the procedure what's being done already . Not sure if this is the way to go here @Thirumalai-Shaktivel !?
Activity
certik commentedon Jan 26, 2023
I think we should implement this. You can change the error message if you want in the meantime.
faze-geek commentedon Jan 27, 2023
Yes sure! I'll be attempting a few PR's once
run_testsstarts correctly working with windows. If I'm not wrong #1463 is a shot at that.anutosh491 commentedon Feb 11, 2023
I've been trying to address this issue , but not sure what approach could be used for the same . Let's say we want to address
Here the iterable we have is of type
AST::List_tand we currently can't address this case but we can address cases where the list has been assigned to a variable .Here the iterable is of type
AST::Name_t. So what comes to my mind for addressing the first case is ... that why don't we assign a dummy name to the list and create an object ofAST::Name_ttype and repeat the procedure what's being done already . Not sure if this is the way to go here @Thirumalai-Shaktivel !?