Fork me on GitHub
#braveandtrue
<
2019-01-17
>
michaels20:01:48

I’m making my way through Brave and True again. Doing chapter 5, peg thing.

michaels20:01:26

The function prompt-move calls itself at the end. Does that ultimately risk the stack? Or if not, how do I know that’s fine?

manutter5120:01:38

Theoretically, it could blow the stack. In this case, that’s unlikely, because it only calls itself when there’s an invalid move. If the move is valid, it takes the other branch of the if-let instead.

michaels20:01:59

the other branch, in turn calls prompt-move again though.

michaels20:01:06

(trampolining?)

michaels20:01:17

I mean, you’re probably going to call the whole thing 30 times max,

michaels20:01:26

but if I was doing a different game - maybe I wouldn’t do that?

manutter5120:01:52

It’s probably still ok, stacks these days are usually pretty big, and you can probably get through enough moves to finish a game before it filled up.

manutter5120:01:10

(I’m saying this based on a rushed reading of the code, so I might be missing something here)

manutter5120:01:58

If I were going to write a turn-taking game, I’d find another way to do it other than writing mutually-recursive calls, because I don’t like trusting that the stack will be big enough, so your instincts are correct IMO.

👍 5
michaels20:01:25

I’ve got a game I’ve almost finished in JavaScript.

michaels20:01:35

My plan is to try to re-write it in clojurescript as a learning exercise.

michaels20:01:43

I’m sure I”m going to be blowing up #beginners and #clojurescript while I do. Thanks for your response!