3 ms·
But how would you express attributes and mixed content and named character entities and namespaces and encoding declarations? S-expressions are beautiful for l
by olavk 19y ago
But how would you express attributes and mixed content and named character entities and namespaces and encoding declarations?
S-expressions are beautiful for lisp code and for many kinds of structured data, but it gets ugly when you try to use it on something as messy as a human-writable hypertext document format. XML syntax on the other hand is designed for this.
- brlewis 19y agohttp://okmij.org/ftp/Scheme/SXML.html http://okmij.org/ftp/Scheme/SXML.html
- olavk 19y agoCool! So bcts example <p>here is a <a href="http://example.com">link</a>.</p> would be: (p "here is a" (a (@ (href "http://example.com")) "link") ".")
- mojuba 19y agoSomething like that, yes, but attributes (a (@ (href /path))...) are ugly in particular. I think it shouldn't necessarily be parsable by Lisp. Attributes, for example, could be as simple as (a (href=/path) ...) Why '=' - because this character is not used in attribute names historically, so with this syntax you can move from XML to Sexp smoothly, automatically that is. Formally, the syntax I suggested is not Lisp, of course.
- omouse 19y agoSomething like that, yes, but attributes (a (@ (href /path))...) are ugly in particular. So use :named attributes instead? (a :href "/path" ...)
- mojuba 19y agoNice indeed, but how about attribute names that themselves contain colons, or maybe start with a colon? XML/HTML is less restrictive in this regard: all that matters basically is spaces and '=' inside a tag.
- omouse 19y agoReplace the colon with a dash in your attribute names. Easy solution.
- tokipin 19y agocontent issues like namespaces wouldn't be unique to s-exp's -- XML had to deal with them. i'm not sure about the readability. i would say XML wins because angle brackets delimit things clearlier, especially by the fact that they're duplicated on closing. but i might have a different opinion if s-exp's were standerer than XML, so i can't really say. some of the SXML examples on that page look really nice --------- don't judge straight translations. if s-exp's were the standard i suspect links would look more like: (p "here is a" (a "link" @href "http://example.com http://example.com" ) )