5 ms·
i'm not sure what you're asking. s-exp's already represent trees: (html (head (title "hi" ) ) (body (h1 "hello" ) ) ) then (defmacro html ... ) to transform
by tokipin 19y ago
i'm not sure what you're asking. s-exp's already represent trees:
(html (head (title "hi" ) ) (body (h1 "hello" ) ) )
then (defmacro html ... ) to transform it. so lisp already has the syntax, the parsers, and the generators
- mojuba 19y agoI understand that's simple in Lisp, but I also need interoperability, and that implies different languages, among other things. Perhaps the reason nobody's adopting Sexp's is that you will never get an answer from lispers, other than "you can do it in Lisp". Great, but I need C++, Perl, then C#, Java, PHP, Python and all kinds of crappy languages to support that format.
- tokipin 19y agolisp syntax is a lot simpler than XML. a basic lisp _interpreter_ would take maybe a night or three in any language, a mere parser much less. but why you don't see many such parsers is a different issue, not closely related to s-exp's themselves
- inklesspen 19y agoSo, why _don't_ you see many such parsers?
- omouse 19y agoGreat, but I need C++, Perl, then C#, Java, PHP, Python and all kinds of crappy languages to support that format. Lucky for you, Greenspun's Tenth Rule (http://en.wikipedia.org/wiki/Greenspun's_Tenth_Rule http://en.wikipedia.org/wiki/Greenspun's_Tenth_Rule) comes into play. All of those languages actually have Lisp embedded inside them: "Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp."
- olavk 19y agoBut 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.