Tuesday, August 16, 2011

JavaScript DSL

I have created a DSL that directly translates to JavaScript.
(function factorial [n]
  (return
    (ternary-operator (== n 0)
      1
      (* n (factorial (- n 1))))))
The above code directly translates into the JavaScript factorial function. Along with prxml, this allows me to create entire web pages entirely in Lisp:
[:html
  [:head
    [:title "Welcome"]]
  [:body
    [:script {:type "text/javascript"}
      [:raw! (to-js '(alert "Hello World"))]]]]
I look forward to being able to use this to develop lots of webpages.

No comments:

Post a Comment