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 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)

gives you: val n = 1024: int

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.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -