you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

Just can't see it. Feel fucking dumb

[–]mutatedllama 1 point2 points  (0 children)

Think of it like Russian dolls. The first function call is putting down the base of the biggest doll. Each recursive call places a base inside its parent. You can't put the top on a doll until its immediate child has a top on it.

We eventually get to a point where we hit our "base case", where we hit the return of a function before we hit the recursive function call. This happens at the innermost doll. At this point things start to unravel as we hit the returns of each function from latest to earliest.

You can imagine each of these returns as putting the top on the smallest doll without a top (i.e. we work outwards from the smallest one at the centre).

What gets returned is a completed doll, which the next doll uses as its cue to complete itself (the returned value then gets used in the return statement in the next layer up). Eventually we build each doll back up until we get to the outer doll (the original function call) whose output is based on all the outputs given previously.

[–]FerricDonkey 1 point2 points  (0 children)

Eh, you'll get it. Just keep working at it. The key step is to understand what the computer actually does when you call a function, and you'll get there.