Jaseci-Labs / jaclang

The Jac Programming Language
https://www.jac-lang.org
22 stars 21 forks source link

[BUG] Incorrect Compilation of 2D List Reverse Syntax #260

Closed AshishMahendra closed 7 months ago

AshishMahendra commented 7 months ago

Describe the bug There is a compilation issue when converting the syntax for reversing a 2D list in Jac, E.g.: two_d_list[::-1];, is incorrectly translated to two_d_list[:-1] in Python. This leads to an unintended slicing of the list, removing the last element, instead of reversing the entire list as expected.

To Reproduce Steps to reproduce the behavior: Example Code:

with entry{     (rows, cols) = (5, 5);     two_d_list = [[i ** j for i in range(cols)] for j in range(rows)];     print(two_d_list);     print(two_d_list[::-1]); }

Output: [[1, 1, 1, 1, 1], [0, 1, 2, 3, 4], [0, 1, 4, 9, 16], [0, 1, 8, 27, 64], [0, 1, 16, 81, 256]] [[1, 1, 1, 1, 1], [0, 1, 2, 3, 4], [0, 1, 4, 9, 16], [0, 1, 8, 27, 64]]

Converted Python Code: from future import annotations rows, cols = (5, 5) two_d_list = [[i ** j for i in range(cols)] for j in range(rows)] print(two_d_list) print(two_d_list[:-1])

Jaclang/Python Version Python version and Jac version, or installed from source. jaclang - 0.4.7 Python - 3.11.6

marsninja commented 7 months ago

Jaclang 0.4.7 is ooooolllldlddd :-P, try on new version and reopen this issue if you find the same problem.