Jscheme is my implementation of Scheme in Java. This page presents Jscheme
version 1.4, the last version that I released (in April 1998). If you want
a mercilessly small, easily modifiable version, this is it.
Since
April 1998, development has been picked up by others, notably
Tim Hickey
at Brandeis and
Ken Anderson
at BBN. If you want the latest, full-featured version, look at:
(method m o cs...) returns a procedure that
invokes a Java method m on an object o. The cs are
names of classes (or class objects) for the arguments of the method.
For example:
(define show (method "show" "java.awt.Frame"))
(show (new "java.awt.Frame"))
Jscheme implements all of R4RS except that:
- Continuations can only be used as escape procedures; that is they
can only be called while the surrounding try/catch is still in
scope.
- read does not handle all the lexical syntax for numbers
(e.g. #e123#.#F-3+#b1/#d4#i). The language standard says "any
particular implementation may support only some" of the written
notations for numbers, so this does not appear to be a violation.
- The distinction between exact and inexact is not right. I represent
all numbers as double precision floating point, and define both
exact? and integer? as
(lambda (x)
(and (number? x)
(= x (round x))
(< (- x 1) x (+ x 1))))
To Do
There are a few things on my "to do" list:
- Better support for errors: catch some errors that kill the system,
allow user to interrupt and get into a break loop or back to top level,
provide for recovery from errors.
- Better integration with Java methods.
- Better way to use multi-threading.
- Functions for web access.
- A GUI.
- An applet version available over the web.
- Add BigInteger or BigDecimal numbers. Or maybe a new
LongRational class.
- Make everything 10 to 50 times faster (I hope) by pre-treating expressions
before evaluating.
- R5RS support. This requires hygienic macros (which
Dorai already did for me) and fifteen new procedures: two-argument
eval, scheme-report-environment, null-environment,
interaction-environment, numerator, denominator, rationalize,
string-copy, string-fill!, vector-fill!, port?, char-ready?, values,
call-with-values, and dynamic-wind. For dynamic-wind,
I will probably have the same limitations as with call/cc.
I believe it is legal to do
(define values list)
(define (call-with-values producer consumer) (apply consumer (producer)))
References
Scheme Standards
- The Revised4 Report on the Algorithmic Language
Scheme (postscript
or HTML). The
version of the standard that Jscheme is currently based on. See also
the r4rstest.scm
compliance test.
- The Revised5 Report on the Algorithmic Language
Scheme (postscript
or HTML). The
very latest version of the standard, also compatible with the IEEE standard.
- IEEE Standard 1178-1990. IEEE Standard for the Scheme Programming Language
(Not available online. You have to buy it from IEEE.)
Scheme Compilation Books
Scheme Implementations (In Java)
- Michael Travers' Skij (Scheme in Java) is similar enough to Jscheme that if Skij had existed, I wouldn't have done Jscheme. Some minor differences: Skij strings are immutable, in violation of Rn Scheme, but in alignment with Java; more of Skij is written in Scheme.
- Per Bothner's Kawa is a
near-complete R5RS Scheme in Java, with many
Common-Lisp-like extensions, that compiles to Java byte codes.
The resulting code is much faster than Jscheme, but Kawa is 605KB
(23K lines) of source code, and 540KB of object code (loaded on
demand); more than 10 times more than Jscheme on both counts.
- Quenniac's PS3I
is a persistent server-side Scheme interpreter written in Java.
General Scheme Resources
- Aubrey Jaffrey's SLIB is a
comprehensive Scheme source code library.
- MIT and Indiana
University maintain home pages for Scheme.
Version History
The table below gives code size measurements in bytes and lines,
for object and source code. "KB" means 1000 bytes, not 1024. "Source"
includes some Scheme code as well as the Java code.
Version Number | *.class KB | classes .jar KB | Source KB | Source lines | Major Changes
|
---|
1.4 | 55KB | 29KB | 69KB | 1905 | No separate scheme file
|
1.3 | 47KB | 28KB | 68KB | 1888 | less scheme code
|
1.2 | 42KB | 26KB | 64KB | 1803 | Better javadoc; no PrintStream
|
1.1 | 41KB | 23KB | 60KB | 1745 | Complete set of R4RS functions
|
1.0 | 40KB | 22KB | 57KB | 1664 | Passed the test suite.
|
Dorai Sitaram (ds26@gte.com) kindly contributed a
R5RS compliant macro-by-example
implementation that works in Jscheme.
Version 1.4: Released April 16, 1998
Version 1.3: Released April 15, 1998
- Put everything in a package.
- Moved everything but some macros from primitives.scm to
Primitive.java. Makes for faster runtime and loading time.
Only increased the number of lines of code by about 50.
- Changed the stringify interface to use a single StringBuffer.
Before, if you had a ten element list, stringify created ten
StringBuffers,
and then merged them into an eleventh. Now its all done in one StringBuffer.
As a matter of fact, it might have been better for Java to provide this kind of
interface for its toString method.
Version 1.2: Released April 10, 1998
- Converted from PrintStream to PrintWriter. No deprecation warnings now.
- Made the error routine throw a RuntimeException.
- Improved javadoc comments.
Version 1.1: Released March 30, 1998.
- Made (1 .2) read as (1 0.2), not (1 . 2).
- Added warning messages that #x and the like are not implemented.
- Added cddddr and the other 3- and 4- c[ad]r procedures.
- Added force and delay.
Version 1.0: Released March 27, 1998.
- First version to pass Jaffrey's test suite.
Peter Norvig