March 14, 2005
ParenScript

Manuel Odendahl's ParenScript is a neat Lisp-like sexpr-based syntax for Javascript (Manuel has more info in this weblog post).

The js macro compiles sexprs into Javascript:

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

==>

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

You can use DO for iteration:

(js
  (do ((i 0 (incf i))
       (j (aref arr i) (aref arr i)))
      ((>= i 10))
    (alert (+ "i is " i " and j is " j))))

==>

for (var i = 0, j = arr[i]; i < 10; i = ++i, j = arr[i]) {
  alert("i is " + i + " and j is " + j);
}

ParenScript has macros:

(defjsmacro 1+ (form)
  `(+ ,form 1))

It also has an HTML generator:

(js
  (defun add-div (name href link-text)
  (document.write
    (html ((:div :id name)
           "The link is: "
           ((:a :href href) link-text))))))


==>

function addDiv(name, href, linkText) {
  document.write("<div id=\"" + name + "\">The link is: <a href=\""
                              + href + "\">s"
                              + linkText + "</a></div>");
}

There's even an sexpr syntax for CSS.

The documentation looks excellent, including a complete reference as well as some tutorials. I'm totally never writing Javascript again.

Posted by jjwiseman at March 14, 2005 03:08 PM
Comments
Post a comment
Name:


Email Address:


URL:




Unless you answer this question, your comment will be classified as spam and will not be posted.
(I'll give you a hint: the answer is “lisp”.)

Comments:


Remember info?