User loginNavigation |
tail recursionHello and sorry if this question has been already answered somewhere, though i searched for it. The question is: tail-recursion is something badly needed _only_ in Scheme? Here's a related question: if it isn't, that is, if it's possible to generally get compilers or interpreters to correctly detect recursion and automatically apply and implicit goto to it, then why should i bother, when it just complicates matters? I gave a though to it when a saw a recent post here about LLVM and its recent support for tail-call for Scheme and also for playing with Haskell a bit. So, to keep things simple, let's look at the examples: ;; in Scheme (define (fact n) (define (product min max) (if (= min n) max (product (+ 1 min) (* min max)))) (product 1 n)) That's one way to look at a factorial, but not the _natural_, i guess. -- in Haskell -- and just to add a bit more argument dec n = n - 1 fact 0 = 1 fact n = fact( dec n ) * n That's the _natural_, let's call it that, high-school definition for factorial, pristine clear. There's no tail-call anywhere to be seen, and yet, it doesn't cause stack overflow with large numbers... Am i missing something? or is Scheme being stubborn? R6RS is coming and perhaps should address it? Sorry for being provocative, but it's a sincere question... By rmalafaia at 2005-05-19 03:59 | LtU Forum | previous forum topic | next forum topic | other blogs | 26376 reads
|
Browse archives
Active forum topics |
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 19 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago