logo       

Re: Tail recursion -> while (?): msg#00240

lang.scala

Subject: Re: Tail recursion -> while (?)

FWIW:

The IBM JVM implements tail call elimination.

Try this code on Sun JVM (you will get a stack overflow):
class Loop {
public static void main(String[] args) {
System.out.println(loop(0));
}

static int loop(int n) {
return loop(n + 1);
}
}

Now try it on the IBM JVM; most times you will get an infinite
computation as the JIT has optimised the tail call.

Tony Morris
http://tmorris.net/



Insitu wrote:
> Iulian Dragos <iulian.dragos@xxxxxxx> writes:
>
>> We don't do that. There are some solutions, for instance see "Tail call
>> elimination on the Java Virtual Machine" by Michel Schinz and Martin Odersky
>>
>> http://citeseer.ist.psu.edu/schinz01tail.html
>>
>
> Really interesting, thx a lot. So basically, scala uses some sort of
> trampolining for tail calls optimisation. Is this roughly correct ? I
> myself ran into the problem when trying to implement an haskell
> compiler for the jvm, and it was not until recently that it occurs to
> trampolining could be a solution. I did not however thought about a
> solution as elegant as shown in the paper.
>
> regards,
>

Attachment: signature.asc
Description: PGP signature

Attachment: signature.asc
Description: OpenPGP digital signature

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise