H
H
hleb12022-03-20 20:53:13
Programming
hleb1, 2022-03-20 20:53:13

What is the difference between a recursive process and a procedure?

I read SICP . There is an explanation of the explanation between a recursive process and a procedure. But I didn't fully understand. Tipo recursive process - this is recursion in all its charms, but the recursive procedure - can create either a recursive process , or iterative (tail recursion)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2022-03-20
@hleb1

From your description, everything seems to be clear.
Here is a recursive procedure (I personally prefer the name of the function). It is recursive by definition - because it directly or indirectly calls itself.
But the process of executing this function can go two different ways, depending on how the function is written, and whether the language implementation supports tail recursion optimization (TCO, Tail call optimization).
If there is no TCO, then the process of executing such a function will be recursive, that is, frames will be created on the stack, and all this can lead to stack overflow (lack of stack memory when calling the function).
Lisp and its dialects have TCO. This means that if the function is written correctly (which means that the recursive call is the last action before exiting the function), then it can be optimized into iteration, and thus save on stack allocations.
Therefore, the process of executing such a function will be iterative. Tail recursion can run indefinitely without stack overflow.
If the function is recursive, but the recursion is not tail, then the process of its execution will be recursive with all the consequences.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question