Conversation
certik
left a comment
There was a problem hiding this comment.
I think this is great, thank you @Agent-Hellboy. I left a minor suggestion.
|
You also need to update our reference tests using: |
src/runtime/lpython_builtin.py
Outdated
| def _lpython_str_join(s:str, lis:list[str]) -> str: | ||
| res:str = "" | ||
| i:i32 | ||
| for i in range(len(lis)): |
There was a problem hiding this comment.
Can be directly iterated on the list itself, this way it can be worked on iterables easily(in future). Every iterable can be called using next so I think that would be more better.
something like this can be more cleaner I think.
for ele in range(list_):
res+=ele
There was a problem hiding this comment.
If it works, we can use the simpler syntax. LPython doesn't yet work for user defined iterables, but eventually it will I think.
src/runtime/lpython_builtin.py
Outdated
| for i in range(len(lis)): | ||
| res+=s | ||
| res+=lis[i] | ||
| return res[1:] |
There was a problem hiding this comment.
thats not reliable. You are always assuming your str len will be 1 here, It should fail when str has len more than 1. You can prob use res[len(str):]
There was a problem hiding this comment.
Good catch! I think even better would be something like:
if len(lis) == 0: return ""
res = lis[0]
for i in range(1, len(lis)):
res += s + lis[i]
return res
There was a problem hiding this comment.
That works too, altho as long as there plans of iterables, part of len will probably be removed regardless.
okay, the CI tests are failing because of this, I didn't understand
|
|
I guess, I need to parse over asr nodes of the list argument passed inside the join method to check if only str is passed or not |
|
It's the one in the root directory: (lp) repos/lpython(main) $ ./run_tests.py --help
usage: run_tests.py [-h] [-u] [-l] [-t [TEST ...]] [-b [BACKEND ...]] [-v]
[--exclude-test [TEST ...]]
[--exclude-backend [BACKEND ...]] [--no-llvm]
[--skip-run-with-dbg] [-s] [--no-color]
LPython Test Suite
options:
-h, --help show this help message and exit
-u, --update update all reference results
... |
That's needed for error messages. But first let's get the two existing tests that you added (they both look great) to pass all CI. After CI passes, then we can either merge, or you can add some tests for errors. |
| test_str_index() | ||
| test_str_slice() | ||
| test_str_repeat() | ||
| test_str_join() |
There was a problem hiding this comment.
Let's test test_str_join2
Thirumalai-Shaktivel
left a comment
There was a problem hiding this comment.
LGTM, Thank you!
| a = "**" | ||
| p:list[str] = ["a","b"] | ||
| res:str = a.join(p) | ||
| assert res == "a**b" |
There was a problem hiding this comment.
We can test more cases like empty strings, more items in the list (more than 3), and so on...
This can be done in the subsequent PRs.
certik
left a comment
There was a problem hiding this comment.
I think this looks good, thanks!
|
I just noticed this. @Agent-Hellboy this is amazing! I really appreciate it. Keep up the great work. |
| ASR::call_arg_t passed_int; | ||
| passed_int.loc = loc; | ||
| passed_int.m_value = args[0].m_value; |
There was a problem hiding this comment.
I just noticed this. Here, I think passed_int should be named list_of_str (or something similar). (@Agent-Hellboy I remember we were experimenting with it by passing an integer.)
I think you can fix the above in your new PR #2364. You can just make the rename a separate commit.
There was a problem hiding this comment.
Go ahead and create an issue, so that we don't forget.
No description provided.