You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
So the problem I was facing was I made a function to index a string and it return a u24 int, is there a way to get the actual letter back or do I need to do the conversion manually (ASCII to letter). Also adding a functionality to type cast for example string number to int is also needed I feel. I couldn't find it anywhere.
Describe the solution you'd like
Function wrappers like Number/Cast ("123") -> returns 123 or String/Cast (101) -> return 'e' can be helpful.
Thanks.
The text was updated successfully, but these errors were encountered:
If you want to see the character as a string, just create a string with a single element.
# This is your String/Cast function
def Number/show(n):
return String/Cons(n, String/Nil)
To read a string as a number, you have to write a number parser
def Number/parse_digit(digit):
return digit - '0'
# This is your Number/Cast function
def Number/parse_decimal(str):
acc = 0
fold str with acc:
case String/Nil:
return acc
case String/Cons:
return str.tail(10*acc + Number/parse_digit(str.head))
I think this works, but it's only to give you an idea.
We don't a builtin way to do either at the moment
developedby
changed the title
Type Casting
Converting between numbers and strings
May 25, 2024
Is your feature request related to a problem? Please describe.
So the problem I was facing was I made a function to index a string and it return a u24 int, is there a way to get the actual letter back or do I need to do the conversion manually (ASCII to letter). Also adding a functionality to type cast for example string number to int is also needed I feel. I couldn't find it anywhere.
Describe the solution you'd like
Function wrappers like Number/Cast ("123") -> returns 123 or String/Cast (101) -> return 'e' can be helpful.
Thanks.
The text was updated successfully, but these errors were encountered: