I’m making my way through Brave and True again. Doing chapter 5, peg thing.
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?
(page 122; https://github.com/flyingmachine/pegthing/blob/master/src/pegthing/core.clj line 223
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.
the other branch, in turn calls prompt-move again though.
(trampolining?)
I mean, you’re probably going to call the whole thing 30 times max,
but if I was doing a different game - maybe I wouldn’t do that?
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.
(I’m saying this based on a rushed reading of the code, so I might be missing something here)
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.
I’ve got a game I’ve almost finished in JavaScript.
My plan is to try to re-write it in clojurescript as a learning exercise.
Cool 🙂
I’m sure I”m going to be blowing up #beginners and #clojurescript while I do. Thanks for your response!
:thumbsup: