ParenScript

A small lispy language that can be compiled to JavaScript

ParenScript is a small lispy language that can be compiled to JavaScript. It also comes with an embedded CSS representation in Lisp. This simplifies the development of web applications in Lisp by allowing the Lisp programmer to write all the documents in Lisp syntax. This way, HTML pages, CSS files and JavaScript code can be generated with the full power of Lisp and its macros.

I'm totally never writing Javascript again.
- John Wiseman, lemonodor.com

Contents

Downloading

The latest version of ParenScript as of October 3, 2006 can be downloaded here:

parenscript-20061003.tar.gz

ParenScript is a part of the UnCommon Web web application development framework, and can be downloaded from their DARCS repository with the following command:

darcs get http://common-lisp.net/project/ucw/repos/parenscript

Thanks to Luca Capello, users of the Debian GNU/Linux system can install the cl-parenscript Debian package by typing the following:

apt-get install cl-parenscript

Manual

The ParenScript manual is split into three parts which are available in PDF format:

Features

  • Supports all the expressions and statements of EcmaScript 262
  • Converts Lisp symbols to java-style camelcase (taken from linj)
  • Lisp-style iteration with DO, DOTIMES, DOEACH, DOLIST
  • Complete macro environment with MACROLET, SYMBOL-MACROLET
  • Uses the Lisp reader for reader macros
  • ParenScript HTML generator for embedding HTML in JavaScript code (no more ugly document.writes)
  • Allows for recursive compilation of ParenScript (generate JavaScript in JavaScript in JavaScript...)
  • Lispy CSS syntax

Examples

An example is worth more than a thousand words. The following Lisp expression is a call to the ParenScript "compiler". The ParenScript "compiler" transforms the expression in ParenScript into an equivalent, human-readable expression in JavaScript. Great care has been given to the indentation and overall readability of the generated JavaScript code.

(js (defun foobar (a b) (return (+ a b))))

The resulting JavaScript is:

function foobar(a, b) { return a + b; }

Here's a real-world example of ParenScript in action:

(defun apply-effect () (when (and document.all photoslider.filters) (let ((trans photoslider.filters.reveal-trans)) (setf (slot-value trans '*Transition) (floor (* (random) 23))) (trans.stop) (trans.apply))))

The generated JavaScript code looks like this:

function applyEffect() { if (document.all && photoslider.filters) { var trans = photoslider.filters.revealTrans; trans.Transition = Math.floor(Math.random() * 23); trans.stop(); trans.apply(); } }

Related Sites

  • ParenScript on CLiki
    A few tutorials and tips are available.
  • ASDF
    Another System Definition Facility. ParenScript depends on this library.
  • UnCommon Web
    ParenScript is a part of this web development framework.
  • CL-INTERPOL
    This library can be handy for writing regexes in ParenScript and is mentioned in the reference manual.
  • JSGEN
    Another library for writing JavaScript using S-Expressions, designed as an extension to AllegroServe.

Authors

ParenScript was written by Manuel Odendahl and Edward Marco Baringer.

Copyright

Copyright (c) 2005-2006 Manuel Odendahl
Copyright (c) 2005-2006 Edward Marco Baringer

License

This software is licensed under the terms of the BSD license. Details are contained within the COPYING file, included within the distribution.

The license was modified to reflect that Manuel Odendahl and Edward Marco Baringer, not the Regents of the University of California, are the authors.