[Programming] Proper Tail Recursion - Bypass recursion limit
|
03-27-2023, 08:37 PM
(This post was last modified: 03-28-2023 08:16 AM by FernandoMorea.)
Post: #1
|
|||
|
|||
[Programming] Proper Tail Recursion - Bypass recursion limit
My research on how to bypass hp prime's recursion limit, coupled with my studies of lisp and haskell, led me to this solution: saving the continuation of a function in a variable, that will be returned to the user, the user must re-run the result to iterate the process.
To cheat the static analysis of the CAS that triggers the recursion limit, we must also define a fake function that simply calls back the main function. The function must be tail recursive: Let's recall what a tail recursive function looks like, let's take the factorial and python as toy language: Code:
So now let's go to our HP PRIME: Code:
Another example could be the algorith for Polynomial long division Code:
|
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
[Programming] Proper Tail Recursion - Bypass recursion limit - FernandoMorea - 03-27-2023 08:37 PM
RE: [Programming] Proper Tail Recursion - Bypass recursion limit - FernandoMorea - 03-28-2023, 06:18 AM
RE: [Programming] Proper Tail Recursion - Bypass recursion limit - FernandoMorea - 03-28-2023, 07:27 AM
|
User(s) browsing this thread: 1 Guest(s)