Scheme in Javascript
Thursday, 19 May 2011
Scheme’s power to simplicity ratio makes it a fun target for implementation. Today, I introduce a couple new ways of running Scheme powered by Javascript.
The first is an online Scheme interface that I’ve been working on sporadically for the last few months. Inspired by TryHaskell, it began as a series of patches to jquery-console, a jQuery terminal-ish plug-in. While my own Scheme-in-Javascript interpreter FoxScheme hasn’t yet reached a very featureful stage yet (macros are the next step), somebody else had created a similar system before me. It was a simple matter to replace FoxScheme with a different back-end system, in this case, Jason Orendorff’s Try Scheme.
About a year and a half ago, Dan Friedman was showing off his new iPhone and mentioned something about not yet having Scheme on it. That stuck in the back of my head, and it wasn’t too hard to make jquery-console work with iPhone by redoing some goofy keycodes. Just point your browser at http://startscheme.com/mobile and try it out. If you are running iOS, you can add an icon to your home screen and it will behave like a web app.
A week ago, I decided to whip together an IDE-like environment for Scheme, along the lines of what SWL or DrRacket present visually, using the all-JavaScript code-editor CodeMirror. Check it out: Scheme online editor. You do need a browser that supports localStorage for the file system to work. The latest Chrome and Firefox should be fine.
I don’t agree with all of the design decisions of Try Scheme, but these things here are just proofs of concept right now.
Even more recently, Fabrice Bellard’s jslinux has been making the rounds. Of course, any Linux system should have some sort of Lisp, right?
TinyScheme was compiled with Bellard’s own TinyCC that he included with jslinux, and seems to run well, although slowly and without many features. You can try it out for yourself at http://startscheme.com/jslinux/ by running “scheme” (note that loading init.scm takes a bit of time!) at the terminal. In addition, I have an archive of just the tinyscheme binary and init.scm, which I actually am allowed to distribute (I believe).
On my might-do list is using Emscripten to compile a more ambitious Scheme compiler to C and running it in the browser.