[ home | photos | gallery | scheme | notes | blog | facebook | twitter | youtube | last.fm | myspace | del.icio.us | EverythingHerePlus ]
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.
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.
The basic preparations for running Kawa under MRJAppBuilder or JBindery are the same.
<local MRJSDK folder>:Tools:Application Builders:MRJAppBuilder
<local MRJSDK folder>:Tools:Application Builders:JBindery
<System Disk>:System Folder:Extensions:MRJ Libraries:MRJClasses:kawa-1.6.70-compiled.jar
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  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]
Figure 1: Setting up MRJAppBuilder to build Kawa
Figure 2: Kawa repl under macos
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]
Figure 2: Kawa repl under macos
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 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.
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.