Kawa internals: Compiling Scheme to Java


Kawa is a set of Java classes useful for implementing dynamic languages, such as those in the Lisp family. Kawa is also an implementation of near-R5RS Scheme using these classes, and which compiles Scheme to the bytecode instructions of the Java Virtual Machine. This paper discusses the various issues involved in implementing Scheme using an abstract machine designed for a very different language. and how Kawa solves these problems.

For information on getting and using Kawa, see the Kawa home page.

This document started out as a paper presented November 1998. Kawa has seen many changes since then, but alas parts of this document are out-of-date.


While Java is a decent programming language, the reason for the Java explosion is largely due to the Java Virtual Machine, and the many packages for it. The JVM allows programs to be distributed easily and efficiently in the form of portable bytecodes, which can run on a wide variety of architectures and in web browsers. These advantages are largely independent of the Java language, which is why there have been a number of efforts to run other languages on the JVM, even though the JVM is very clearly designed and optimized for Java. Kawa is both a toolkit for compiling other languages into Java bytecodes, and an implementation of the Scheme language implemented in Java. Kawa also incorporates Qexo, an implementation of the XQuery language, and JEmacs, a partial implementation of the Emacs Lisp extension language.

The benefits of this hybrid Scheme/Java environment include:

  • Provides a higher-level, more dynamic programming interface than Java, with support for scripting and interactive read-eval-print loops.

  • Extends the Java benefits of "write once run anywhere" to Scheme programs, including portable bytecode distribution and web applets, though the use of standard Java bytecodes.

  • Full integration between Java and Scheme: Scheme programs can call Java methods, and Java methods can call Scheme procedures.

  • Scheme programs benefit from the extensive efforts in improved Java implementations, optimizations, environments, and tools.

  • Scheme programs get access to the large library of standard Java classes.