braveandtrue

https://www.braveclojure.com/
michaels 2019-01-17T20:21:48.023300Z

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

michaels 2019-01-17T20:22:26.024100Z

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?

michaels 2019-01-17T20:22:42.024400Z

(page 122; https://github.com/flyingmachine/pegthing/blob/master/src/pegthing/core.clj line 223

2019-01-17T20:27:38.025600Z

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.

michaels 2019-01-17T20:27:59.026200Z

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

michaels 2019-01-17T20:28:06.026600Z

(trampolining?)

michaels 2019-01-17T20:28:17.027100Z

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

michaels 2019-01-17T20:28:26.027600Z

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

2019-01-17T20:28:52.028200Z

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.

2019-01-17T20:29:10.028600Z

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

2019-01-17T20:30:58.029600Z

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.

👍 1
michaels 2019-01-17T20:31:25.030Z

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

michaels 2019-01-17T20:31:35.030400Z

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

2019-01-17T20:34:06.030600Z

Cool 🙂

michaels 2019-01-17T20:37:43.031Z

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

2019-01-17T20:38:46.031200Z

:thumbsup: