package main /* * Recursion depth testing in Go. * run this using go run recur.go 2> /dev/null * this will grab the stack trace and throw it ways so that the trace does not clog the terminal * Created: sep 20, 2023 * gtowell */ import "fmt" func recur1(p int64) { if p%100000==0 { fmt.Println(p); } recur1(p+1); } const ii=10000 // this has depth very similar to recur1 and is unaffected by changes to ii func recur2(p int64) { var aa [ii]int64 aa[p%ii]=p if p%ii==0 { fmt.Println(p); } recur2(p+1) } // depth much less that recur 1 // affected by changes to ii func recur3(p int64) { var aa [ii]int64 aa[p%ii]=p if p%100==0 { fmt.Println(aa[p%ii]); } recur3(p+1) } func main() { // change this to recur2 or recur3. recur3(0) }