lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.5k stars 158 forks source link

Add compile-time support for `list.pop` #2659

Closed kmr-srbh closed 5 months ago

kmr-srbh commented 5 months ago

Working

from lpython import i32

print([1, 2, 3, 4, 5].pop())
print([1, 2, 3, 4, 5].pop(3))

index: i32 = 1
print([1, 2, 3, 4, 5].pop(index))

element_1: i32 = [1, 2, 3, 4, 5].pop()
print(element_1)

element_2: i32 = [1, 2, 3, 4, 5].pop(2)
print(element_2)

print([(1, 2), (3, 4), (5, 6)].pop(1 - 0))
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
5
4
2
5
3
(3, 4)