To test Gambit’s portability I have built the latest Gambit with Emscripten to run it in the browser. To try it out visit this URL:
http://gambitscheme.org/emscripten-gambit.html
The system supports many features, including Gambit’s R7RS module system. It comes with a preloaded virtual filesystem. The REPL supports the same features as on the desktop, including emacs keybindings, parenthesis matching, tab completion, and the REPL history is preserved from one execution to the next (in the browser’s local storage).
To ease experimentation, you can execute JavaScript code with the jseval procedure:
(jseval "prompt('please enter your name')")
"spiderman"
(current-directory)
"/home/web_user/"
(directory-files)
("fib.sld" "demo.scm")
(load "demo.scm")
(time (fib 25)) 0.494000 secs real time 0.000000 secs cpu time (0.000000 user, 0.000000 system) no collections 7788120 bytes allocated no minor faults no major faults "/home/web_user/demo.scm"
Embedding the Gambit REPL in a web page is as simple as including the file emscripten-gambit.js in the web page, and putting emscripten_gambit.wasm on the server with the .js file:
<!doctype html> <html lang="en-us"> <head> <title>Emscripten compiled Gambit in the browser</title> </head> <body> <script type="text/javascript" src="emscripten-gambit.js"></script> </body> </html>
The script for building Gambit with emscripten is in misc/build-emscripten-gambit.tgz
Have fun!
Marc