jsScheme
is a nearly complete implementation of R5RS Scheme language in
JavaScript. It is described on Chris Double's website in a
2006 blog post.
Archive.com has captured
the page on its Wayback Machine.
The code can be run online on
a page of Chris Double's website
or on
Archive.com's capture.
That version forms the initial commit to this Git repository.
Archive.com also has
captures of Alex Yakovlev's earlier, original version of jsScheme,
although those captures might not be working.
jsScheme
runs inside this web page.
Possibly jsScheme be divided into four parts:
-
The Core Part containing just JavaScript code, having no dependencies upon any HTML, that maintains the Scheme environment and evaluates Scheme expressions and outputs Scheme results;
-
the Experimenter's Part containing just the user input
<textarea>
, the Result cell, and code to connect it to the Core Part; -
the Implementer's Part containing part containing the Log
<textarea>
, the Symbols table, and code to connect it to the Experimenter's Part; and -
the Interactive Introduction Page containing a text introduction to jsScheme and links to background information and code to connect it to the Implementer's Part.
The Core Part will utilities for jQuery and HTML, and Alexander Sukhoverkhov's
shift
, reset
, remove-handler!
, with-handlers
,
and get-input
.
The Interactive Introduction Page will contain links to important and
useful background material:
- Proper tail-recursion.
- First-class continuations, even with
dynamic-wind
. - Boolean, string, number, char, and vector data types, but no complex or rational numbers.
- Limited
syntax-rules
transformer (written in Scheme; no nested ellipsis ('...') or vectors support). - Optional just-in-time compilation to javascript. This does not
support continuations. The library can be pre-compiled with
(compile-lib)
and inserted in theinit
function. This will speed up loading at the price of ~200kB. Download it. - Almost no error checking.
- No I/O like
load
,read-char
,open-input-file
, etc. - Limited
values
support. Only the first value is displayed. All continuations may receive multiple values, not only those created withcall-with-values
:
(values 1 2 3) => 1
(+ (values 1 2 3)) => 6
(list (values 1 2 3)) => (1 2 3)
(call-with-values (lambda () (values 1 2 3)) +) => 6
- Predicates like
=
andstring>?
take only 2 arguments, but can be extended in this way:
(define < ((lambda() (define old< <)
(lambda (x y . rest)
(if (old< x y)
(if (null? rest)
#t
(apply < y rest))
#f)))))
(< 1 2 3 4 5) => #t
(< 1 2 3 4 3) => #f
map
works on improper lists:
(map + '(1 2 . 3) '(40 20 . 10)) => (41 22 . 13)
(map + 14 9) => 23
- Most of the R⁵RS features and library are implemented.
- Passes all
r5rs_pitfall.scm
tests (included in SISC). - Strings are immutable; no
string-fill!
andstring-set!
. begin
,lambda
,if
,define
,set!
andquote
. are primitive language expressions. They are not derived as R5RS defines. Moreover,lambda
bodies with several statements are enclosed inbegin
in internal representation to emphasize that they express different concepts: the first is a function and the second is an operators sequencing.- Tested in IE6 and Opera7.
Chris Double wrote a blog post about a bug, captured by Archive.org, in the Scheme-to-JavaScript just-in-time (JIT) compiler.
Copyright (c) 2003 by Alex Yakovlev. All rights reserved. Can be freely redisributed under GPL, version 2 terms.
-
R. Kent Dybvig, The Scheme Programming Language, Second Edition.
-
Alex Yakovlev's old Lisp interpreter in C (source unknown).
-
Per Bothner's Kawa, both an interpreter and compiler-to-Java-bytecode.
-
Skij, captured by Archive.org, from the same group at IBM's T.J. Watson Research Center who developed Jikes, moved to Sourceforge.net.
-
SISC - Second Interpreter of Scheme Code, R5RS compliant.
-
Bigloo compiler, very efficient, can produce Java bytecode.