0
$\begingroup$

According to Wikipedia, and also a very common definition of a recursive function found in several books, "functions that call themselves from within their own code". I agree that this solves the problem for most of what I think recursive functions are, but, suppose you have the following "iterative" code written in C:

int foo(){
    return 2;
}

The unique pourpose of this function is to compute the value "2". Can we say this is also a "recursive" function? Saying it only relies in a base case. I can see the function isn't calling itself in their body, even though, I can't find a way to compute it in another way, using the self-calling part.

Besides, I'm aware of the fact that every iterative function has a recursive implementation, so, in this case this function does have the same implementation for the iterative and for the recursive view?

$\endgroup$
4
  • $\begingroup$ Computer science definitions must be interpreted literally. Since there is no call, it is not recursive. $\endgroup$ – beroal Jun 15 '20 at 7:41
  • $\begingroup$ @beroal I see. How can I give a recursive definition of a constant function? $\endgroup$ – Jay Jay Jun 15 '20 at 14:52
  • $\begingroup$ For example, return true ? 2 : foo(); in C. $\endgroup$ – beroal Jun 15 '20 at 20:16
  • $\begingroup$ @beroal but in a general way? In a mathematical way? $\endgroup$ – Jay Jay Jun 15 '20 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.