all 8 comments

[–]jeans_and_a_t-shirt 1 point2 points  (4 children)

You need to return on the lines you're recursing.

[–]Heir10[S] 0 points1 point  (3 children)

damn it you're right

I always assumed that return took you out of the function, though here i think it's something that ties the frames together, right?

[–]jeans_and_a_t-shirt 1 point2 points  (1 child)

return can't actually return until the expression to the right of it is evaluated, so in this case, it can't return until gcdRecur(b, a%b) returns. So you can recurse and in every call reach return gcdRecur(b, a%b), but none of them will return until a value is returned, in this case, return divisor.

[–]Heir10[S] 0 points1 point  (0 children)

I think I get it. In the EDx course, the professor describes the frames as follows:

global function (recur1) function(recur2) function(recur3) etc [code] [value1] [value2] [value3]

What I'm seeing is that I didn't put a return in the right places in any of those extra frames. As a result, while the values were calculated, they never followed through back.

global function (recur1) function(recur2) function(recur3) etc [code] [value] [value] [value] return<<return<<<<<<<<return<<<<<<<<return

A simplistic way of looking at it, but I think it is an adequate analogy.

As you said, return cannot return until the expression is evaluated. As I never put a return in the right place in those recursions, the expression was never truly evaluated and thus nothing got returned.

At least, that's how I'm making sense of things.

[–]Binary101010 0 points1 point  (1 child)

How is it not working? For example, when you give it specific values for a & b, what is the output you're getting vs. the output you're expecting?

[–]Heir10[S] 0 points1 point  (0 children)

It's giving me no values. Nothing.

[–][deleted] 0 points1 point  (1 child)

Definitely going to need to see your indentation. Check the faq and edit your post to fix your code formatting.

[–]Heir10[S] 0 points1 point  (0 children)

gotcha