Hacker News new | ask | show | jobs
by ghusbands 3213 days ago
In Lisp, if you created something like JSX, your IDE or text editor would still be unlikely to understand it, as it'd be a very complicated reader macro. It doesn't magically solve all macro problems.

Doing it the Lispy way, though, you'd likely use sexprs directly, with maybe some normal macros, so you wouldn't have HTML-like syntax but would have something that worked nicely in your editor.

2 comments

SXML has been around a while, and makes working with HTML in most Lisps a breeze. See this for example [0].

    '((html (head (title "My Title"))
         (body (@ (bgcolor "white"))
               (h1 "My Heading")
               (p "This is a paragraph.")
               (p "This is another paragraph."))))
[0] http://www.neilvandyke.org/racket/html-writing/
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.