@Jake223 I know where you're coming from, but you could also say that a structure like a linked list is recursively defined (the definition has a base case and an recursive step), and there's no doubt that recursive functions are self-referential.
–
CalebJan 4 '13 at 22:23

Here are the two tag definitions on Stack Overflow: Recursion in computer science is a method of problem solving where the solution to a problem depends on solutions to smaller instances of the same problem. Self-reference is the ability of a program (or logical sentence) to refer to itself, either directly or indirectly.
–
infinitesimalJan 4 '13 at 21:12

And for tags, that seems about right. You don't want to get into odd corner cases for a tag. And it's probably about the level you want to think of now as well.
–
jmorenoJan 5 '13 at 9:12

Those two calls to fibonacci() inside the fibonacci() function are recursive calls.

Here's a self-referential data structure:

struct ListNode {
char *data;
struct ListNode *next;
}

The first element, data, is just a pointer to some sort of data. The second element, next, is a pointer to another ListNode structure. If you have two or more ListNode structures, you can set the next pointer of one to the address of another, and so on, and you then have a linked list. The structure is self-referential because the definition of the structure refers to itself. If you want to get really crazy, you could do this:

Now you've got a different kind of self-reference -- it's not just the definition of struct ListNode that refers to itself... you've set the next pointer of node to point to node itself. This is a circular linked list containing only one element. Cute, but not very useful. I mention it because it's a kind of self-reference, but it's not what people usually mean when they talk about self-referential data types.

Is it correct to say that recursion is a special case of self-reference where the object being referred to (or called) is a function?
–
infinitesimalJan 4 '13 at 5:35

2

Sure, you could say that a recursive call is a form of self reference. Sometimes the terms are nearly interchangeable, although not with respect to code. For example, most people would call "GNU" a "recursive acronym" because it stands for "GNU is Not Unix", but nobody would say that you were wrong if you called it a "self-referential acronym" instead.
–
CalebJan 4 '13 at 5:54

@Caleb This is not a particularly good example, because List is a recursive data type. So you are actually showing another example of recursion!
–
Andres F.Jan 4 '13 at 20:26

@AndresF. Can you give an example of a self-referential data structure that's not a recursive data type? Sources like this and this use the term 'self-referential' for structures like linked lists while others use 'recursive'. If my answer fails to make a clear distinction between the terms, it's because the terms aren't exactly synonymous, but are very close in meaning.
–
CalebJan 4 '13 at 21:03

@Caleb Oops, sorry. If you are saying they are very close in meaning, then we agree and I misunderstood you!
–
Andres F.Jan 4 '13 at 21:09

If you define recursion as a construction being carried over a well-founded relation, then the fact a recursion does not terminate corresponds to an infinite decreasing sequence -- and therefore the self-referential "recursion" is not at all a recursion. This is much like how an algorithm is required to stop at some point.
–
Asaf KaragilaJan 4 '13 at 0:58

5

What about this statement: "This sentence has five words." It's self-referential, but I don't see any nonterminating recursion. I also don't think recursion generally has to involve self-reference. If you compile a recursive C function into binary machine code, the machine code doesn't have any self-reference in it. I think the most you can say is that a terminating self-reference is one possible way of defining a recursion.
–
Ben CrowellJan 4 '13 at 1:42

2

Yes, this my explanation is by no way perfect. I am just trying to simplify in case "OP is trying to interpret some self references as recurances." I no way mean self references are always non terminating recursions.
–
user1710036Jan 4 '13 at 1:50

Is it correct to say that recursion is a special case of self-reference where the object being referred to (or called) is a function?
–
infinitesimalJan 4 '13 at 5:32

Recursion requires something to process via calling the same process (often with different parameters). Even though you're often using functions and those functions call themselves, they technically enter a new step that just happens to look like the place they just came from.

Self-Reference means that something refers to itself. Classes can be self-referential by using this, but that's not meaningfully recursive.