The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

doki (5) [Avatar] Offline
#1
Hi Amit,

In section 8.1.1 you talk about tail calls, specifically stating that the JVM doesn't support them.

However, there's nothing in the JVM to prevent tail-call optimisation by the compiler (Scala does it). It can be easily represented in bytecode using goto or possibly even jsr.

See "Programming the Java Virtual Machine" by Joshua Engel (1999)

Cheers, and thanks for a great book (so far) from a Clojure newbie!
amitrathore (132) [Avatar] Offline
#2
Re: tail calls are easy in bytecode
You're right of course. Right now, Clojure uses the Java compiler, so this restriction exists ... Thanks for your encouragement, glad you're enjoying the book!
richhickey (1) [Avatar] Offline
#3
Re: tail calls are easy in bytecode
The JVM cannot do arbitrary TCO. You can only do self recursion, or, in limited contexts, mutual recursion. See John Rose's response here:

http://mail.openjdk.java.net/pipermail/mlvm-dev/2010-October/002017.html