|
Re: Tail recursion -> while (?): msg#00240lang.scala
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, >
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Scala in .Net and VisualStudio.NET: 00240, Nikolay Mihaylov |
|---|---|
| Next by Date: | pattern matching works strange for an O'Caml programmer: 00240, Alexander Sergeev |
| Previous by Thread: | Re: Tail recursion -> while (?)i: 00240, Insitu |
| Next by Thread: | Re: Tail recursion -> while (?): 00240, Michel Salim |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |