- edit I think I see what you are saying, I must not really understand the concept of primitive recursion (or non-, not sure which I don't understand)
- edit I think I see what you are saying, I must not really understand the concept of primitive recursion (or non-, not sure which I don't understand)
Primitive recursion is equivalent to a 'for' loop with a pre-computed bound, e.g. 'for i in [0..X]: ...'.
Recursion that's "non-primitive" would include general recursion, which places no restriction on how we recurse; e.g. we could recurse on the next state of a Turing Machine. General recursion is equivalent to a 'while' loop which re-computes its condition after each iteration.
"Non-primitive" recursion can also include other restricted forms of recursion, which do not allow general computation, but cannot be represented by a primitive-recursive form; for example, the (usual definition of the) Ackermann function mentioned in the article takes two arguments, and its recursive calls can increase the second argument (so it's not primitive recursive). However, the pair of arguments always decrease according to (x, y) < (x, y+1) (if the first argument stays the same, the second argument must decrease) and (x, y) < (x+1, z) (if the first argument decreases, we can use anything for the second argument). The latter condition is so permissive that the Ackermann function is allowed to recurse with a second argument that is itself the result of another recursive call. This grows so fast that the number of loop iterations required to implement it cannot be computed by a primitive-recursive function (whatever function we try, there will eventually be an input that requires more iterations than that function returns).
while(true){
}
and f=()=>f()
In the sense that f will at one point call a function in a function in ... and in some languages this will cause an error (maximum call stack). Also I think in some languages: in memory is stored some context that allows us to know how to "get out" of the function f, and within each recursive call of f, memory usage grows (I am no expert).F is recursive. While is iterative.
An iterative process can be recursive or not.
And once you look at procedures that use two stacks, like this[1], then it becomes pretty apparent just how arbitrary the distinction is.
I mean that anything iterative looks to me like a simple (linear) case of recursion. But I can imagine a series of calls that is recursive but not linearly iterative.
Unfortunately some "poorly designed language implementations"[0] will fail to run such functions, with the "stack overflow" you mention.
[0] https://en.wikisource.org/wiki/Lambda:_The_Ultimate_GOTO