2 ms·
> Hi. I've been coding for over 20 years. Do you think it likely that "arguably you don't understand recursion"? If you thought the only recursive thing in exi
by catnaroek 10y ago
> Hi. I've been coding for over 20 years. Do you think it likely that "arguably you don't understand recursion"?
If you thought the only recursive thing in existence is recursive procedures, yes, arguably you didn't understand recursion. (Which is fine, by the way - you can be a very successful programmer without understanding recursion.)
> Perhaps where we were at cross-purposes is that when I said recursion I meant recursive procedure but you were thinking of recursive data structures (and possibly also of recursive procedures).
When anyone says recursion, I understand recursion. Limiting your idea of “recursion” to recursive procedures is like limiting your idea of “black” to black T-shirts.
> Why I contradicted you was that I didn't think your parent/ancestor example was a good explanation for recursive procedures but, yes, I now see that it is a good explanation of a recursive data structure.
My parent/ancestor example was an example of a recursively defined relation, not a data structure. (I deliberately picked an example that most programmers wouldn't relate to code.) In Prolog it could be written:
ancestor(X,Y) :- parent(X,Y).
ancestor(X,Z) :- parent(X,Y), ancestor(Y,Z).
Where `parent(X,Y)` means “Y is a parent of X”, and `ancestor(X,Y)` means “Y is an ancestor of X”.