Kamen Lisp

Creating specialized web pages using dynamic techniques (DHTML) has until now mostly been the domain of Javascript, a language often described as "Lisp disguised as C". Kamen Lisp changes this, by shedding the C syntax, and allowing web pages to operate with pure, standard compliant Common Lisp. This Firefox extension uses ECL to host a lisp environment, interfacing with the existing Javascript engine only when necessary.

Download

preview version 0.94

Version 0.94 has a number of upgrades:

  • Arbitrary javascript functions may be called.
  • Calling lisp from html events uses a lispy syntax.
  • Each page uses a separate space for variables.
  • Error propogation is much better, though still needs some work.
  • Overall stability improvements.

The security model in Kamen Lisp is still a bit experimental. There is a whitelist, so only sites you allow to run lisp can, but still run Kamen Lisp at your own risk. It is recommended that you run Kamen Lisp under a different profile.

Source

source 0.94 download

The source is covered by the MPL-GPL-LGPL tri-license.

Building takes some effort. You'll need the gecko sdk, the Firefox source, and a patched and built ECL. Patch is included in the source, and is needed for both the security model and better cooperation with Firefox. On Windows, the MSVC compiler is recommended.

Usage

All script tags that have the attribute language="text/common-lisp" are executed as normal: top-level code is run after the page loads, and functions defined like (defun func () ...) are callable later, using the following syntax: <input type="button" onclick="(func)">

Performing dom manipulation is done by calling the special form (dom object action &rest args).

Examples:

(dom document :get-element-by-id :input-value)
document.getElementById("inputValue");

(dom input :inner-html)
input.innerHTML

Note that symbols may be for method names, object properties, and element id's. For method names and object properties, the symbol name is case-insensitive and dashes are ignored. For element id's, all letters are assumed to be lower case, except those following dashes. This shouldn't be a problem as the page author should also have control over what id names are used.

The (dom ...) special form is both used to retrieve values in object properties and call methods. It is also setf-able. When it is necessary to resolve ambiguity, you may also use its less general cousins:
(dom-get object property)
(dom-set object property value)
(dom-call object method &rest args)

Demo Pages

Sierpinski's Gasket: Draw Sierpinski's Gasket on a canvas. Demonstrates using lispy data structures naturally in applications, and also how javascript interface works.

Fib Lisp: Calculate Fibonacci numbers using lisp. Simple example of how lisp in script tags works. Uses macros to memoize function calls. Demonstrates how Kamen Lisp does DHTML. Also shows how HTML buttons can call lisp in script tags.

Todo:

  • Improve performance.
  • Better error reporting and handling.
  • Provide support for the cleaner 'addEventListener' technique.
  • Documentation.