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

range with step doesnt stop before stop #12

Open
jayvdb opened this issue Jul 1, 2021 · 2 comments
Open

range with step doesnt stop before stop #12

jayvdb opened this issue Jul 1, 2021 · 2 comments

Comments

@jayvdb
Copy link

jayvdb commented Jul 1, 2021

for i in range(0, 10, 2):
    print(i)

should emit 2->8, stepped by two

The transpiler emits

for i in 0.step(10, 2)
    print(i)
  end

which emits 2->10, stepped by two

@nanobowers
Copy link

nanobowers commented Jul 3, 2021

@jayvdb
Existing testcases didn't catch this one..
Ruby uses a greater than, whereas python is a greater-than/equal-to for positive steps

But this seems a little tricky to do "in-place" as the range step may be ascending or descending.

I'm not sure how much this deviates from the original philosophy of trying to do as much as possible in-line, but I think an additional range-function: PyLib.range() on the ruby side that closely maps to python's behavior is the best way to proceed in terms of correctness - at the expense of having to include the module using either the -r/-b options for py2rb.

@jayvdb
Copy link
Author

jayvdb commented Jul 3, 2021

I am open to either approach. py2many transpilers usually have a supporting library to deal with Python, and I am already adding a -r .../py2rb/builtins/module.rb in my wrapper. However most also implement Python range by doing +1 or -1 on the args in-place. See https://github.com/adsharma/py2many/search?q=visit_range

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

2 participants