rds :: graphikos

[ home | photos | gallery | scheme | notes | blog | facebook | twitter | youtube | last.fm | myspace | del.icio.us | EverythingHerePlus ]

Kawa Scheme System on Macintosh

Also on This Site
Kawa and Kawa-Mac Resources
Kawa Scheme System on Macintosh OS X Current
Kawa Scheme System on Macintosh OS X 10.1
Kawa Scheme System on Macintosh OS Classic
Kawa Notes, Downloads, Caveats
Running Kawa in Emacs

Mac OS Classic Instructions

Per Bothner's Kawa Scheme: a Scheme interpreter written in the Java with bindings to the Java language. The system allows compilation of Scheme code directly to Java Bytecodes. As Kawa is designed to run from command line, additional measures are needed to run it on the Macintosh. Although these instructions seem lengthy at first glance, the process is really quite simple.

Software Requirements
Installation and Runtime under MRJAppBuilder
Installation and Runtime under JBindery
Using JEmacs with Kawa on Macintosh

Software Requirements

In addition to the Kawa package, you need the latest MRJ and MRJ SDK software installed on the Macintosh. Kawa may run under older version of MRJ, but its best to use current Apple Java software. If you are running a version of Mac OS X, please let me know how you would recommend running Kawa if it differs from the standard Unix distributions. All versions listed are current of this document's last revision on 03/21/2001.

Apple Java software
MRJ 2.2.4 Mac OS Java runtime
MRJ 2.2.2 SDK
Kawa Java software
This information is outdated, please go to downloads for binaries that work with OS9!
Only one kawa.jar file is needed, pick the version you want from this list. You may want to check the [1] Getting Kawa page or the Kawa ftp directory for revisions.
Kawa 1.6.70 (latest snapshot)
Kawa 1.6.1 (current stable version)
Kawa 1.6.71 (unofficial) unofficial build configured with-swing, compiled and packaged myself, it runs, passes the test-suite, and has JEmacs integrated.
Optional Java software
Sun's JFC/Swing 1.1.1 Foundation Classes


The basic preparations for running Kawa under MRJAppBuilder or JBindery are the same.

  1. If necessary download and install the current version of MRJ (Mac OS Runtime for Java)
  2. Download and install the current version of the MRJ SDK
  3. Depending on whether you want to use MRJAppBuilder or JBindery Java applications builders, locate the folder containing the application builder within the MRJ SDK folder installed on your system. You may want to create an alias or copy of the application builder folder you are going to be using in your Kawa development folder. The paths should be as follows:
    <local MRJSDK folder>:Tools:Application Builders:MRJAppBuilder
    <local MRJSDK folder>:Tools:Application Builders:JBindery
  4. Download a version of the kawa.jar file (ie. kawa-1.6.70.jar). Your ftp package or browser may mistakenly type the file. Insure that the file's creator code is "java" and its type is "ZIP " (last character is a space). There is an AppleScript in the kawa-mac distribution package that can help with this.
  5. Place a copy of the kawa-1.6.xx.jar file in the MRJ classpath by placing it in your MRJClasses folder. The directory path should look like:
    <System Disk>:System Folder:Extensions:MRJ Libraries:MRJClasses:kawa-1.6.70-compiled.jar

Installation and Runtime under MRJAppBuilder

Creating the Properties file

MRJAppBuilder requires that you create a '.properties' file that contains the command line flags and other information required to build and run Java applications. It is probably best to name the file the same as the output application, for example 'kawa-mac-1.6.71.properties' for a final application of kawa-mac-1.6.71. An example properties file is available in the kawa-mac distribution package.

Kawa can take a wide variety of command line flags. If you are familiar with these, you may want to experiment with them for various projects. Comment lines begin with the pound character '#' and are used here to illustrate what each line does. For a full explanation of the available properties under MRJAppBuilder, please see the 'MRJAppBuilder properties' documentation that comes with the MRJ SDK. The minimum lines in the properties file to have the Kawa repl run are:

com.apple.mrj.application.main = kawa.repl
	# the kawa read-evaluation-print-loop
com.apple.mrj.application.parameters = -w
	# this command line flag creates a new window for the repl see [1] Command-line arguments
com.apple.mrj.application.classpath = $BOOTCLASSPATH
	# specifies runtime code location for kawa, in this case the standard MRJ classpath
com.apple.mrj.application.stdin = $CONSOLE
	# get stdin from console/repl window
com.apple.mrj.application.stdout = $CONSOLE
	# send stdout to console/repl window
com.apple.mrj.application.stderr = /$APPLICATION/kawa-errors.log
	# send stderr to error file located in same directory as the kawa runtime binary
com.apple.mrj.application.stderr.append = true
	# appends stderr error file as opposed to overwriting it

With the properties file completed, the creation of the Kawa binary is fairly simple. The MRJAppBuilder takes up to three file names: first the target application which is the name for the final binary, then the configuration file which is the '.properties' discussed above, and optionally the files to merge into the target application which is the packaged classes for Kawa. If the files to merge is omitted, MRJ assumes the classes for runtime are located in the MRJ classpath, see Preparations for more information on this. Clicking the 'Select' and or 'Add...' buttons and then navigating to the correct files in MRJAppBuilder will take care of typing the lengthy path information for you. An even easier way to do this is by dragging kawa-1.6.xx.jar and '.properties' files onto the MRJAppBuilder icon in the Finder. It will automatically fill in the path information.

With the necessary file information provided in MRJAppBuilder, click the 'Build' button. Status and or errors will display in the Java console window. If the console displays 'Executing: MRJAppBuilder [snipped]' and 'Done' on a new line, you have built kawa-mac with no errors. The unofficial build configured with-swing builds with no errors, some .jar file versions will generate errors, but not all of them are show stoppers if the line 'Done' still appears in the console. MRJAppBuilder should create a Java application with the name provided in the 'target application' field in the same directory as itself (this is why you may want to have a copy of MRJAppBuilder in your working directory). This runtime will behave as any other Macintosh application, you should be able to double click its icon launch it. If all goes well, you should be able to use the REPL at the #|kawa:1|# prompt. Type in Scheme expressions to evaluate them, see the Kawa manual for instructions on bytecode compilation, etc. [fig. 2]

MRJAppBuilder setup screenshot
Figure 1: Setting up MRJAppBuilder to build Kawa

Kawa screenshot
Figure 2: Kawa repl under macos

Installation and Runtime under JBindery

JBindery offers the quickest way to set up Kawa, although Apple seems to be migrating towards the use of MRJAppBuilder (probably because it uses PPC startup code). Launch JBindery, In the Command panel type kawa.repl in the Class Name field, -w in the Optional Parameters field, set Message Window for Redirect stdout, and Message Window for Redirect stdin.

You can run a Kawa session by clicking the 'Run' button, or save the settings to a stand alone application by clicking the 'Save Settings...' button and insuring that the 'Save as Application' option is checked before saving. Once Kawa is running you should be able to use the REPL at the #|kawa:1|# prompt. Type in Scheme expressions to evaluate them, see the Kawa manual for instructions on bytecode compilation, etc. [fig. 2]

JBindery screenshot
Figure 3: JBindery setup

Kawa screenshot
Figure 2: Kawa repl under macos

Using JEmacs with Kawa on Macintosh

JEmacs requires Sun's JFC/Swing, see Optional Java software under Software Requirements above for information on obtaining and installing it. See the JEmacs site for JEmacs revisions. Not every build of Kawa seems to include JEmacs. A quick way to get JEmacs running under kawa-mac is to download the current JEmacs jar file and install it in the standard MRJ classpath (MRJClasses folder). When correctly installed the directory path for JEmacs should look like this:

<System Disk>:System Folder:Extensions:MRJ Libraries:MRJClasses:jemacs.jar

You evoke JEmacs from Kawa by typing (emacs) at the repl. A separate window appears with the JEmacs interface.

JEmacs screenshot
Figure 4: Running JEmacs

JEmacs doesn't seem to be in sync with the most current versions of Kawa. When the separate jemacs.jar version is in use it will cause Kawa to report the wrong version when (scheme-implementation-version) is called. This doesn't happen when JEmacs is built into to Kawa with the 'with-swing' directive at configure. The unofficial build was created this way and doesn't require the separate jemacs.jar file to be installed.


For several current known issues and workarounds, please see Kawa Caveats, Notes, Downloads.

Java, hence Kawa, uses Unix style paths. This is important if you are accessing Scheme files from disk. The following shows the difference for pathnames in MacGambit-C versus Kawa:

  (load "Faragis:Scheme Source:calc-e3d-fov.scm") ; MacGambit-C
  (load "/Faragis/Scheme%20Source/calc-e3d-fov.scm") ; Kawa under MRJ

An excellent source for Scheme-Java implementations is the Languages for the Java VM page. Peter Norvig's SILK page also lists several other Scheme-Java implementations and links. Kawa's author has published Papers describing the technical aspects of Kawa. They are very informative and great guides for implementing languages on the Java Virtual Machine. Kawa is more at home under Unix. If you run any of the PowerPC BSD or Linux variants, you might want to do Kawa development there instead.


Kawa, the Java-based Scheme system
Using JBindery, Apple Computer, Inc. 1998
About JBindery, Apple Computer, Inc. 2000
About MRJAppBuilder, Apple Computer, Inc. 2000
MRJAppBuilder properties, Apple Computer, Inc. 2000