Control Stack Size
1. Dilemma
While I was testing my basketball website, specifcally the play by play stats, the entire website crashed when loading one of the pages. Prior to this crash, the website had never gone down when loading a page. So this error came as a surprise to me.
As show in the image there is an error, "Control stack exhausted (no more space for function call frames), is "probably due to heavily nested or infintely recursive function calls."
2. Understanding the Dilemma
The dilemma ended up being due to the list of arguments
exceeding the call-argument-list. This was a result of using
the
apply
function in a few of my other functions. With
apply
every time it it runs through an argument, it "stacks the
value" because it is a non-optimized recusion function. If it
"stacks" enough times where it reaches a limit it invokes the
"Control stack exhausted."
3. Solution
Instead I used the function
reduce
where
it repeats the function with two functions. This essentially "optimizes"
as it goes through the arguments so there wont be the "stacks" that would
have happened had
apply
been used.