tail-call-optimization

What Is Tail Call Optimization?

Very simply, what is tail-call optimization? More specifically, Can anyone show some small code snippets where it could be applied, and where not, with an explanation of why? ...

How is Tail Call Optimization implemented in DrScheme?

I've heard that trampolining is an ineffective way of implementing TCO. How does DrScheme (PLAI Scheme, technically) do it? Does it do it the 'right' way (that is, produce assembly code which directly branches to the tail call, instead of going through the stack and trampolining)? ...

Why is Garbage Collection Required for Tail Call Optimization?

Why is garbage collection required for tail call optimization? Is it because if you allocate memory in a function which you then want to do a tail call on, there'd be no way to do the tail call and regain that memory? (So the stack would have to be saved so that, after the tail call, the memory could be reclaimed.) ...

Difference between JVM implementations

Where do JVM Implementations differ (except licensing)? Does every JVM implement Type Erasure for the Generic handling? Where are the differences between: JRockit IBM JVM SUN JVM Open JDK Blackdown Kaffe ..... Deals one of them with Tail-Call-Optimization? ...

Is GHC able to tail-call optimize IO actions?

Will GHC perform tail-call optimization on the following function by default? The only weird thing about it is that it is recursively defining an IO action, but I don't see why this couldn't be TCO'd. import Control.Concurrent.MVar consume :: MVar a -> [a] -> IO () consume _ [] = return () consume store (x:xs) = do putMVar store x ...

How do I know if a function is tail recursive in F#

I wrote the follwing function: let str2lst str = let rec f s acc = match s with | "" -> acc | _ -> f (s.Substring 1) (s.[0]::acc) f str [] How can I know if the F# compiler turned it into a loop? Is there a way to find out without using Reflector (I have no experience with Reflector and I Don't know C#)?...

Explain to me what the big deal with tail call optimization is and why Python needs it

So apparently, there's been a big brouhaha over whether or not Python needs tail call optimization. This came to a head when someone shipped Guido a copy of SICP because he didn't "get it." I'm in the same boat as Guido. I understand the concept of tail call optimization. I just can't think of any reason why Python really needs it. ...

What would the jvm have to sacrifice in order to implement tail call optimisation?

People say that the clojure implementation is excellent apart from the limitation of having no tail call optimisation - a limitation of the jvm not the clojure implementation. http://lambda-the-ultimate.org/node/2547 It has been said that to implement TCO into Python would sacrifice stack-trace dumps, and debugging regularity. h...

Does Xcode for the iPhone eliminate tail-call recursion?

Does Xcode support tail-call optimization on the iPhone? ...

Does PL/SQL perform tail call optimization?

I'm fairly new to the language, and I was wondering if tail calls were optimized. In other language I could examinate the machine code or an intermediate representation and figure it for myself but I have no idea about how to do that in PL/SQL. Thanks in advance. ...

What is tail-recursion elimination?

Steve Yegge mentioned it in a blog post and I have no idea what it means, could someone fill me in? Is it the same thing as tail call optimization? ...

Are programs in functional languages more likely to have stack overflows?

I am starting to learn ocaml, and am really appreciating the power of recursion in the language. However, one thing that I am worried about is stack overflows. If ocaml uses the stack for function calls, won't it eventually overflow the stack? For example, if I have the following function: let rec sum x = if x > 1 then f(x - 1) + x...

Why is Clojure much faster than Scala on a recursive add function?

A friend gave me this code snippet in Closure (defn sum [coll acc] (if (empty? coll) acc (recur (rest coll) (+ (first coll) acc)))) (time (sum (range 1 9999999) 0)) and asked me how does it fare against a similar Scala implementation. The Scala code I've written looks like this: def from(n: Int): Stream[Int] = Stream.cons(n, from(n+...

Tail calls in architectures without a call stack.

My answer for a recent question about GOTOs and tail recursion was phrased in terms of a call stack. I'm worried that it wasn't sufficiently general, so I ask you: how is the notion of a tail call (or equivalent) useful in architectures without a call stack? In continuation passing, all called functions replace the calling function, and...

gcc -fPIC seems to muck with optimization flags

Following along from this question: how-do-i-check-if-gcc-is-performing-tail-recursion-optimization, I noticed that using gcc with -fPIC seems to destroy this optimization. I am creating a shared library, but I doesn't seem to need the -fPIC option. Well, my question is, why does -fPIC change gcc optimizations ? Do I need to keep -fPIC ...

Tail Call Elimination in Clojure?

Can somebody rewrite this (plt) Scheme code into Clojure? (define (f n) (printf "(f ~a)~n" n) (g n)) (define (g n) (printf "(g ~a)~n" n) (h n)) (define (h n) (printf "(h ~a)~n" n) (f (+ n 1))) In such a way as to not collapse the procedures f, g, and h together and to allow the code to run indefinitely without cras...

The Definitive Tail-Call Recursion Question

After participating in the debate in this fiascoquestion, I would like to posit the question before the entire community. In what scenarios will tail-call optimization be applied to .Net-based code? Please support your answers with reliable, up-to-date sources or reproducible experiments. ...

Visual C++ Tail Call Optimization

According to answers to that question: Which, if any, C++ compilers do tail-recursion optimization? it seems, that compiler should do tail-recursion optimization. But I've tried proposed options and it seems that compiler can't do this optimization in case of template functions. Could it be fixed somehow? ...

What is the Scala annotation to ensure a tail recursive function is optimized?

I think there is @tailrec annotation to ensure the compiler will optimize a tail recursive function. Do you just put it in front of the declaration? Does it also work if Scala is used in scripting mode (for instance using :load <file> under REPL)? ...

C tail call optimization

I often hear people say that C doesn't perform tail call elimination. Even though it's not guaranteed by the standard, isn't it performed in practice by any decent implementation anyhow? Assuming you're only targeting mature, well implemented compilers and don't care about absolute maximum portability to primitive compilers written for...