tomelam / jsScheme

Scheme interpreter in JavaScript

Home Page:http://www.bluishcoder.co.nz/jsscheme/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jsScheme--Scheme in JavaScript

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:

  1. 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;

  2. the Experimenter's Part containing just the user input <textarea>, the Result cell, and code to connect it to the Core Part;

  3. the Implementer's Part containing part containing the Log <textarea>, the Symbols table, and code to connect it to the Experimenter's Part; and

  4. 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:

  1. background.html

  2. quickref.html

  3. A Sequential Web-Application Demo

Features

  1. Proper tail-recursion.
  2. First-class continuations, even with dynamic-wind.
  3. Boolean, string, number, char, and vector data types, but no complex or rational numbers.
  4. Limited syntax-rules transformer (written in Scheme; no nested ellipsis ('...') or vectors support).
  5. Optional just-in-time compilation to javascript. This does not support continuations. The library can be pre-compiled with (compile-lib) and inserted in the init function. This will speed up loading at the price of ~200kB. Download it.
  6. Almost no error checking.
  7. No I/O like load, read-char, open-input-file, etc.
  8. Limited values support. Only the first value is displayed. All continuations may receive multiple values, not only those created with call-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
  1. Predicates like = and string>? 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
  1. map works on improper lists:
	(map + '(1 2 . 3) '(40 20 . 10))  =>  (41 22 . 13)
	(map + 14 9)  =>  23
  1. Most of the R⁵RS features and library are implemented.
  2. Passes all r5rs_pitfall.scm tests (included in SISC).
  3. Strings are immutable; no string-fill! and string-set!.
  4. begin, lambda, if, define, set! and quote. are primitive language expressions. They are not derived as R5RS defines. Moreover, lambda bodies with several statements are enclosed in begin in internal representation to emphasize that they express different concepts: the first is a function and the second is an operators sequencing.
  5. Tested in IE6 and Opera7.

Bugs

Chris Double wrote a blog post about a bug, captured by Archive.org, in the Scheme-to-JavaScript just-in-time (JIT) compiler.

License

Copyright (c) 2003 by Alex Yakovlev. All rights reserved. Can be freely redisributed under GPL, version 2 terms.

References

  1. R. Kent Dybvig, The Scheme Programming Language, Second Edition.

  2. Revised 5 Report on the Algorithmic Language Scheme R⁵RS.

  3. Structure and Interpretation of Computer Programs.

  4. Oleg Kiselyov's Scheme page.

  5. Kirill Lisovsky's Scheme page, captured by Archive.org.

  6. PLT Scheme.

  7. Alex Yakovlev's old Lisp interpreter in C (source unknown).

Other Implementations in JavaScript

  1. Luke Gorrie's, captured by Archive.org.

  2. Douglas Crockford's.

  3. Joe Ganley's, relocated to joeganley.com.

Implementations in Java

  1. Per Bothner's Kawa, both an interpreter and compiler-to-Java-bytecode.

  2. Skij, captured by Archive.org, from the same group at IBM's T.J. Watson Research Center who developed Jikes, moved to Sourceforge.net.

  3. SISC - Second Interpreter of Scheme Code, R5RS compliant.

  4. Bigloo compiler, very efficient, can produce Java bytecode.

About

Scheme interpreter in JavaScript

http://www.bluishcoder.co.nz/jsscheme/


Languages

Language:HTML 39.3%Language:Scheme 32.3%Language:JavaScript 28.4%