recursion - recursive function to convert string to integer ML -
I have to write my own recursive function in mL that in any way to convert the string of numbers to integer types Ord is used. I can use the helpful function, but apparently I should be able to do this without using it (according to my professor).
I think the input is valid, and it is a positive integer
Then, call str2int ("1234") output to 1234: int
me It seems that there will be a need to use explosion and rotation at some point as the ED is running on the character, and my input is a string, any direction will be highly appreciated.
You can define an auxiliary function gives you: As you are seeing, intermediate results have to pass on each recursive call in the next step. This is a very common technique in dealing with these types of problems. charstoInt Processes on the left side. In each step it converts the leftmost digit
c to a number and with 10x-multi,
n (which is the median amount of all the precursors in the past) ...
Fun Characters ([], N) = N | CharsToInt (c: cs, n) = charsToInt (cs, 10 * n + ord c-48) val n = charsToInt (explosion "1024", 0)
val n = 1024: int
Comments
Post a Comment