5 ms·
This is interesting. It reminds me of the API behind JSX. But I'm not sure what problem this is seeking to solve exactly. Is it showing that HTML and s-expressi
by Lowkeyloki 7y ago
This is interesting. It reminds me of the API behind JSX. But I'm not sure what problem this is seeking to solve exactly. Is it showing that HTML and s-expressions are technically interchangeable?
- txru 7y agoIf you have time, this[0] is the canonical article usually shared around this concept. The thrust of it is that yes, XML (or x-expressions) and s-expressions are very similar, and that s-expressions are a less verbose and simpler way to represent data. [0] https://www.defmacro.org/ramblings/lisp.html https://www.defmacro.org/ramblings/lisp.html
- jakear 7y agoSkimmed the article, left me a bit confused. Am I missing something big, or is this not particularly novel? The similarities between a-expressions and XML seem fairly obvious to me.
- txru 7y agoWell, it is and isn't novel. S-expressions have been around since McCarthy, XML since the mid-90's. The point of the article is that XML is a more verbose re-interpretation of s-expressions-- it's hard to find things that XML brings to the table that sexps don't have. What's more, inside editors, there are really clever things that manipulate sexprs, move them around, redefine their semantic meaning. XML usually doesn't work quite that way, not as a first intent.
- tannhaeuser 7y agoSGML has been around since the 1960s, and XML is specified as a proper subset of it. SGML/XML isn't so much about (trivial) nesting than it is about content models, eg. the language defined by a regular expression admitted/recognized as the content of a particular element. Markup is also first and foremost a plain text format, optionally tagged by start-/end-element tags, unlike sexprs which need quotes around individual spans of text. Try telling an author to use verbose quoting (and escaping for quotes) for what makes the majority of his text format, or try edititing a large text with verbose sexpr yourself, and you'll see why nobody uses sexprs for semistructured text.
- txru 7y agoI take your point, and I really don't want to be the spark of a syntactic flamewar. I suspected I was missing something, and that the $angle_bracketed_format was older, but I was searching the wrong things. It seems to me, though, that escaping is just something that's going to be tricky everywhere, and a decent first line solution, wherever you are, is to have a really rare set of characters represent your begin/end string marks. In Python, """text""", Postgres has $$text$$, non-ASCII characters in other formats. XML and sexps are both susceptible to that issue-- both of their escapes are, themselves, escapable. To either one, if you have a subregion that's likely to be unintentionally escaped, then you create a boundary where you either explicitly escape every one, or you refuse to acknowledge previously accepted delimiters. As an example, lisps have (quote term) rather than 'term when you're writing macros and concerned with macro-expansion. To your regex point, there are lisps that definitely did awful deeds with that, particularly emacs lisp, but the more recent ones have solutions just like other modern programming languages and markups do. To me the unending escape just kind of seems like a universal bug. While lisp is just as susceptible, lisps have perfectly reasonable ways of treating these problems-- separate, make distinct, and as last resort, escape.
- goto11 7y agoSGML came out of document authoring and publishing. SGML is more suited for this domain because (among other things) you don't have to quote every single string. It is not like the SGML community didn't know about s-expressions - DSSSL the style language for SGML was based on scheme, so they recognized s-expressions were appropriate for some domains.
- neilv 7y agoIt'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
- js8 7y agoActually, there is a fundamental difference between XML and sexps. In XML, text is unescaped, while the metadata are escaped. In sexps, the metadata are unescaped, while the text is escaped. Most text formats fall into one of these two categories. Formats primarily for storing text (like XML or SGML or TeX) are in the former, formats primarily for storing (unstructured) data (like sexps or JSON or YAML) are in the latter.