Skip to content

Commit

Permalink
Implement runtime len function
Browse files Browse the repository at this point in the history
  • Loading branch information
namannimmo10 committed Feb 25, 2022
1 parent 5ddc5c4 commit 25bede7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/runtime/lpython_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,16 @@ def bool(x: i32) -> bool:
return False
else:
return True


def len(s: str) -> i32:
"""
Return the length of the string `s`.
"""
if s == '':
return 0
count: i32
count = 0
while s[count:-1] != '':
count += 1
return count + 1

0 comments on commit 25bede7

Please sign in to comment.