Hacker News new | ask | show | jobs
by davexunit 3211 days ago
Lisp comes with a built-in templating system: quasiquote. Systems such as SXML (an s-expression representation of XML documents) build on top of that. This takes care of multiple problems with JSX: 1) writing HTML/XML is annoying (remembering to put the close tag in the right place, etc.) 2) JSX is a DSL, not an embedded DSL, so you need new compiler infrastructure to work with it.

Here is a snippet of real code that produces an SXML tree. It generates atom feeds for websites that use a static generator I wrote:

    `(feed (@ (xmlns "http://www.w3.org/2005/Atom"))
           (title ,(site-title site))
           (subtitle ,subtitle)
           (updated ,(date->string* (current-date)))
           (link (@ (href ,(string-append (site-domain site)
                                          "/" file-name))
                    (rel "self")))
           (link (@ (href ,(site-domain site))))
           ,@(map (cut post->atom-entry site <>
                       #:blog-prefix blog-prefix)
                  (take-up-to max-entries (filter posts))))
By far the best templating system I've ever used.