I have written this recursive function in Kotlin:
fun recursive(target: String, population: Population, debugFun: (String) -> Unit) : Population {
if (population.solution(target).toString() == target) {
return population
}
debugFun.invoke(population.solution(target).toString())
return recursive(target, population.evolve(target), debugFun)
}
It will run an indeterminate amount of times (because I'm using randomness to converge on solution in evolutionary algorithm). I am frequently getting stack overflow. What is the maximum stack depth for Kotlin/JVM languages? Should i just write the function non recursively?