lcompilers / lpython

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

Add support for printing symbolic list #2527

Open faze-geek opened 7 months ago

faze-geek commented 7 months ago
from sympy import pi
from lpython import S

def main0():
    l: list[S] = [pi]
    print(l)

main0()

(lp) C:\Users\kunni\lpython>src\bin\lpython --enable-symengine try.py
[94581235565888]
anutosh491 commented 7 months ago

Yeah I had given a thought on this, some days back and I think we could surely address this.

The way to do it would be very similar to how list assignment is being resolved through the symbolic ASR pass. So we go from snippet 1 to snippet 2

// snippet 1
l1: list[S] = [x]

// snippet 2
_l1 : list[CPtr] = [x]
l1: List{CPtr] = []

for i in range(len(_l1)):
    tmp: CPtr = basic_new_heap()
    l1.append(tmp)
    basic_assign(l1[i], _l1[i])

This can be addressed similarly 1) Create a temporary list for l of type list[Str] 2) Use a for loop going over length of l 3) append basic_str(l1[i]) to temporary list 4) print(temporary list)