4 ms·
Initially this was the reason and I still do this, but it should be noted that Racket, for example, will treat the following examples exactly the same and will
by 59nadir 12y ago
Initially this was the reason and I still do this, but it should be noted that Racket, for example, will treat the following examples exactly the same and will do just fine with the non-tail recursive example (as far as I can tell):
(define (sum/recursive/opt lst [sum 0])
(if (null? lst)
sum
(sum/recursive/opt (rest lst)
(+ sum (first lst)))))
(define (sum/recursive/non-opt lst)
(if (null? lst)
0
(+ (first lst)
(sum/recursive/non-opt (rest lst)))))
I don't use any other variants of Scheme with any meaningful frequency, but I still use the uppermost variant because I'm just used to it.