lpython icon indicating copy to clipboard operation
lpython copied to clipboard

Add support for printing symbolic list

Open faze-geek opened this issue 1 year ago • 1 comments

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]

faze-geek avatar Feb 12 '24 05:02 faze-geek

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)

anutosh491 avatar Feb 12 '24 05:02 anutosh491