On 04/02/2009 07:31 AM, Jon Harrop wrote:
> I want to make sure I've got my facts straight, both in order to make an
> informed decision myself and to inform others accurately. Specifically, I am
> considering diversifying into Scala and/or Clojure and I need to know whether
> or not the elimination of tail calls may become reliable in those languages
> in the relatively-near future. If not, that is a serious impediment for
> functional languages and will rule out all JVM-based languages for me.

A number of JVM-based languages implement tail-call elimination.
The problem is that you have to compile your functions into a
different calling convention that the natural. which has some
performance cost, and complicates interoperability.

Kawa supports two calling conventions, selected by a command-line
switch:
(1) The "obvious" one where a Scheme function call is translated to
a plain method call, with the methods return value being the Scheme
function's result.
(2) Full tail-call support using an extra hidden method argument
that points to a CallContext object.  A call is translated thus:
- The parameters are evaluated, and copied into the CallContext.
- The function to be called is evaluated and saved in the CallContext.
- The calling function returns.
- That function's caller implements a "trampoline" (see
http://en.wikipedia.org/wiki/Tail_recursion and
http://en.wikipedia.org/wiki/Trampoline_%28computers%29 )
which then calls the function saved in the CallContext.
- The callee methods extracts its arguments from the CallContext.

This is obviously a bit slower, but not so much slower as
to be unusable.  (The CallContext API isn't as tweaked as
it should be.)

The two calling conventions can interoperate, in the sense that
a function compiled with convention (1) can call a function
compiled with convention (2) and vice versa.

On 04/02/2009 09:46 AM, Ben Evans wrote:
 > As I understand it, it is not currently possible to implement
 > Scheme fully on the JVM, as the Scheme spec requires compilers to
 > make a form of the above MUST guarantee (I am not a Scheme head, so > 
 > if this is too much of a simplification, someone please put me right).

You're right about Scheme, but wrong about it not being possible
to implement Scheme fully on the JVM.

In adding to tail-call-elimination full continuations are a
problem.  Kawa doesn't implement those, but there are Scheme-on-JVM
implementations that do.  (There is no reason Kawa can't implement
full call/cc, as an option at least - it's just more complexity and
overhead, and other things have had higher priority.)
-- 
        --Per Bothner
p...@bothner.com   http://per.bothner.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to jvm-languages@googlegroups.com
To unsubscribe from this group, send email to 
jvm-languages+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to