Comments on: Scala tail recursion and decompiler adventures http://eikke.com/scala-tail-recursion-decompiler/ 'cause this is what I do Tue, 04 Dec 2012 00:03:23 +0000 hourly 1 http://wordpress.org/?v=3.4.1 By: Jim http://eikke.com/scala-tail-recursion-decompiler/comment-page-1/#comment-35604 Jim Sat, 05 Jun 2010 06:19:31 +0000 http://eikke.com/?p=129#comment-35604 "Yea and I always wonder how Java handles recursive calls. I always feel that I can’t get more than 3000 calls on some of the most basic code. I figure with the default 64MB jvm heap size, I sure hope the JVM can take more than that. " The limitation on the number of nested calls is determined by the (per-thread) stack size, not the heap size. This can be expanded with -Xss jvm parameter. “Yea and I always wonder how Java handles recursive calls. I always feel that I can’t get more than 3000 calls on some of the most basic code. I figure with the default 64MB jvm heap size, I sure hope the JVM can take more than that. ”

The limitation on the number of nested calls is determined by the (per-thread) stack size, not the heap size. This can be expanded with -Xss jvm parameter.

]]>
By: Nicolas http://eikke.com/scala-tail-recursion-decompiler/comment-page-1/#comment-26508 Nicolas Thu, 13 Aug 2009 11:32:46 +0000 http://eikke.com/?p=129#comment-26508 Ismael, I saw that while browsing the Scala sources, indeed :-) Still on 2.7 though, looking forward to 2.8! Ismael, I saw that while browsing the Scala sources, indeed :-) Still on 2.7 though, looking forward to 2.8!

]]>
By: Ismael Juma http://eikke.com/scala-tail-recursion-decompiler/comment-page-1/#comment-26506 Ismael Juma Thu, 13 Aug 2009 10:03:05 +0000 http://eikke.com/?p=129#comment-26506 Hi, A very useful addition to Scala 2.8.0 (unreleased) is the @tailrec annotation. That allows you to tell the compiler to issue an error if it's unable to apply the optimisation. Best, Ismael Hi,

A very useful addition to Scala 2.8.0 (unreleased) is the @tailrec annotation. That allows you to tell the compiler to issue an error if it’s unable to apply the optimisation.

Best,
Ismael

]]>
By: Nicolas http://eikke.com/scala-tail-recursion-decompiler/comment-page-1/#comment-26503 Nicolas Thu, 13 Aug 2009 07:18:55 +0000 http://eikke.com/?p=129#comment-26503 @Simon: I can imagine :-) Using *any* functional construct in a primarily imperative language/environment might cause issues, but I do think having notions of functional concepts and techniques can also benefit imperative programmers and code quality. @Berlin: Regarding number of arguments, I didn't test it yet, but I expect things to work out fine, at least until 22 arguments (looks like 22 is the largest function arity in the Scala library: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk/src/library/scala/). @Daniel: Thanks for the information, although I don't really see how that applies here: why can't the Scala compiler emit bytecodes which immediately identify 'next' to be of type V? I might be missing something... Don't know Java bytecodes at all, might need to peek into them one day. @Simon: I can imagine :-) Using *any* functional construct in a primarily imperative language/environment might cause issues, but I do think having notions of functional concepts and techniques can also benefit imperative programmers and code quality.

@Berlin: Regarding number of arguments, I didn’t test it yet, but I expect things to work out fine, at least until 22 arguments (looks like 22 is the largest function arity in the Scala library: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk/src/library/scala/).

@Daniel: Thanks for the information, although I don’t really see how that applies here: why can’t the Scala compiler emit bytecodes which immediately identify ‘next’ to be of type V? I might be missing something… Don’t know Java bytecodes at all, might need to peek into them one day.

]]>
By: Daniel Gonzalez http://eikke.com/scala-tail-recursion-decompiler/comment-page-1/#comment-26502 Daniel Gonzalez Thu, 13 Aug 2009 06:33:37 +0000 http://eikke.com/?p=129#comment-26502 "the only thing I don’t get is why ‘next’ is an Object and not a ‘V’" That's due to the way Generics work in Java: They only exist at compile time. JVM does NOT know a thing about Generics, it keeps on dealing with Object. As somebody said, Generics is "syntactical sugar". That also mean that you can't rely on Generics for run time checks, because that information has been lost when transalated to bytecode. “the only thing I don’t get is why ‘next’ is an Object and not a ‘V’”
That’s due to the way Generics work in Java: They only exist at compile time. JVM does NOT know a thing about Generics, it keeps on dealing with Object. As somebody said, Generics is “syntactical sugar”.

That also mean that you can’t rely on Generics for run time checks, because that information has been lost when transalated to bytecode.

]]>
By: Berlin Brown http://eikke.com/scala-tail-recursion-decompiler/comment-page-1/#comment-26501 Berlin Brown Thu, 13 Aug 2009 03:39:36 +0000 http://eikke.com/?p=129#comment-26501 "the code was failing with the inevitable " Yea and I always wonder how Java handles recursive calls. I always feel that I can't get more than 3000 calls on some of the most basic code. I figure with the default 64MB jvm heap size, I sure hope the JVM can take more than that. To the Scala code, have you tested if you increase the number of parameters in your reduce method. I wonder if Scala will ever default to the Java recursive call if you have too many args. “the code was failing with the inevitable ”

Yea and I always wonder how Java handles recursive calls. I always feel that I can’t get more than 3000 calls on some of the most basic code. I figure with the default 64MB jvm heap size, I sure hope the JVM can take more than that.

To the Scala code, have you tested if you increase the number of parameters in your reduce method. I wonder if Scala will ever default to the Java recursive call if you have too many args.

]]>
By: Simon http://eikke.com/scala-tail-recursion-decompiler/comment-page-1/#comment-26497 Simon Wed, 12 Aug 2009 23:12:41 +0000 http://eikke.com/?p=129#comment-26497 Ran into an ugly little bit of Java code recently, that surely must have been written by a functional-language programmer - splitting a comma-separated string, implemented by tail recursion. Never mind that Java has better ways of splitting strings, such methods really don't work under the JVM - the code was failing with the inevitable StackOverflowException... Ran into an ugly little bit of Java code recently, that surely must have been written by a functional-language programmer – splitting a comma-separated string, implemented by tail recursion. Never mind that Java has better ways of splitting strings, such methods really don’t work under the JVM – the code was failing with the inevitable StackOverflowException…

]]>