3 ms·
It's obvious to any Lisp person, and very convenient, in some wasys. A few things usually going on with S-expression representation of XML or HTML encoding in
by neilv 7y ago
It's obvious to any Lisp person, and very convenient, in some wasys.
A few things usually going on with S-expression representation of XML or HTML encoding in a Lisp:
1. It uses some of the native basic types of Lisp -- the list, the symbol, and the string.
2. The HTML element values that you type in your source and that are displayed to you are generally in the same syntax, since that's how Lisps tend to work with the basic types. (For contrast, you don't type your HTML like `<html><body><p>Hi</p></body></html>` in your source, and then see it in the debugger like `HtmlElement#abcd1234("html", {HtmlElement#c948f447("body", {HtmlElement#e7e7e7e7("p", {HtmlCdata#c8c8c8c8c8("Hi")})})})`.
3. The S-expression printed representation you see in your source can be less verbose than HTML or XML, such as by not needing HTML element end tags. Though you will have to put your HTML CDATA text as quoted string literals.
4. A Lisp person's typical code indenting (supported by the editor), tends to expose the tree/forest structure of HTML conveniently:
(html (head (title "My Page"))
(body (p "First paragraph.")
(blockquote "Don't quote me on that.")
(div (p "Another paragraph.")
(p "Yet another paragraph."))
(p "Hey, it's a paragraph.")))
Note that I probably wouldn't type a huge book this way. I might instead use Markdown or a DSL or alternate reader, such as Scribble or its at-reader, mainly to get TeX-like paragraphs: https://docs.racket-lang.org/scribble/ https://docs.racket-lang.org/scribble/ https://docs.racket-lang.org/scribble/reader-internals.html https://docs.racket-lang.org/scribble/reader-internals.html
- tannhaeuser 7y ago> The S-expression printed representation you see in your source can be less verbose than HTML, such as by not needing HTML element end tags Tag inference/omission in SGML (and by extension HTML when seen as an application of SGML) is way more powerful. A minimal, valid HTML document is this: <title>Whatever title</title> <p>Text goes here SGML's tag inference, when coupled with a DTD for HTML5 such as mine [1], will treat that as equivalent to this: <html> <head> <title>Whatever title</title> </head> <body> <p>Text goes here</p> </body> </html> See details in slides or paper linked from [2]. [1]: http://sgmljs.net/docs/w3c-html51-dtd.html http://sgmljs.net/docs/w3c-html51-dtd.html [2]: http://sgmljs.net/blog/blog1701.html http://sgmljs.net/blog/blog1701.html
- neilv 7y agoNeat that you've done this for HTML5. Early Web browsers tended to do some of that (with less-rigorous semantics, some of which I approximated in my early HTML parser). Consequently, Web pages in practice often did, too. Maybe that could make manual writing of documents in HTML5 more practical. For bits of HTML embedded in code lately, I've preferred a simpler model and syntax using S-expressions, but I could see the implied tags as very useful for handwriting documents SGML-style.