31 ms·
Using s-expressions instead of XML
- ch 17y agoI'll just leave this here: http://okmij.org/ftp/Scheme/xml.html http://okmij.org/ftp/Scheme/xml.html
- csmeder 17y agoIt is still cool that he came up with this on his own.
- zitterbewegung 17y agoYea although he goes a little further with scheme.
- uriel 17y agoNice! And a good time to remember Erik Naggum's epic S-exps vs. XML rant: http://harmful.cat-v.org/software/xml/s-exp_vs_XML http://harmful.cat-v.org/software/xml/s-exp_vs_XML
- dschobel 17y agoRobbery is not just another way of making a living, rape is not just another way of satisfying basic human needs, torture is not just another way of interrogation. And XML is not just another way of writing S-exps. There are some things in life that you do not do if you want to be a moral being and feel proud of what you have accomplished. It distresses me that someone could type that up and think it reasonable and worth sharing.
- uriel 17y agoIt distresses me that so many people can't appreciate Naggum's genius :(
- Confusion 17y agoMany people can appreciate any genius. They can't appreciate incoherent rants that wander from technical points to politics to cultural criticism to analogies doomed to distract any reader from the technical points. You will be recognized as a genius when you make insightful arguments others can follow and which teach them something; not when you require them to wade through a pile of irrelevant drivel, as if it was a high school exercise in summarising. Erik doesn't even make arguments. He just states things, like Remove the syntactic mess that is attributes. (You will then find that you do not need them at all.) Yeah, that's a really solid argument, that immediately convinced me that seperating syntactically between metadata elements and child data elements is not necessary...
- gloob 17y agoIf you find that so distressing, I wonder how you feel about this little tidbit from Swift: I have been assured by a very knowing American of my acquaintance in London, that a young healthy child well nursed, is, at a year old, a most delicious nourishing and wholesome food, whether stewed, roasted, baked, or boiled; and I make no doubt that it will equally serve in a fricasie, or a ragoust. There are types of writing that do not revolve around literally and bluntly saying what you mean. I rather doubt that Mr. Naggum actually believes that XML is morally comparable to rape, in much the same way that I rather doubt Mr. Swift was seriously arguing that the Irish should begin eating their children.
- dschobel 17y agoTo compare one of the greatest works of satire with Eric's vitriol belies a fundamental ignorance or insincerity. What Eric wrote is puerile condescending crap. But please, quote me an ironic passage of Shakespeare to reiterate Mr. Naggum's subtle genius.
- gloob 17y agoTo compare one of the greatest works of satire with Eric's vitriol belies a fundamental ignorance or insincerity. I would hope neither, obviously, though it's entirely possible I'm wrong. I would rather just discuss the writer's actual point rather than his stylistic decisions or personality flaws.
- loup-vaillant 17y agoTo simplify things a bit, I would suggest the use of angle brackets instead of parentheses: <tagname <@ attr "value" attr2 "value2"> <tagname2> <tagname3 "data">> Going a bit further, we could require the `@`, and place it after the attributes list. This format has fewer special cases: <tagname attr "value" attr2 "value2" @ <tagname2 @> <tagname3 @"data">> Finally, we could remove the quotes around the raw strings ("data"), while inverting the brackets: >tagname attr "value" attr2 "value2" @ >tagname2 @< >tagname3 @data<< This may look twisted, but we stay very close to true S-expressions, while using the same escape characters we have in plain XML.
- loup-vaillant 17y ago[meta] Can someone tell me which line did I cross? I thought my comment above was more than noise.
- Robin_Message 17y agoI think you may have been voted down because the form you have made is not close to S-expressions at all. Sexps are a direct way of encoding a tree of symbols, values and other trees - nothing else. To give an example of why this is powerful, suppose I decide I need two different namespace of attributes. In your example, this is hard. I can either do: >tagname attr "value" @ attr "value2" !< which special cases the parsing, and is hard to understand, or >tagname ns1:attr "value" ns2:attr "value2" @< which makes it hard to process attributes (xml is like this) Sexps have an easy, obvious solution (tagname (@ attr "value") (@other attr "value2")) which I'd argue is clearer, more backward compatible, and doesn't require changing the parser. Now this is only one example, but the point of sexps is they don't have an special cases, and they move the semantics out of the syntax and into the processing.
- wingo 17y agoClose is not enough -- part of the attraction of s-expressions is that they are part of the language. Thus you can use the language's escaping mechanisms, or put the escaping in your sxml->xml filter. Preserving XML escapes is not actually a virtue. If you enter your data using S-expressions and validate on transformation, you will never have malformed XML. (Not in any way that matters, anyway: http://validator.w3.org/check?uri=http%3A%2F%2Fwingolog.org%2F&charset=%28detect+automatically%29&doctype=Inline&group=0 http://validator.w3.org/check?uri=http%3A%2F%2Fwingolog.org%...) edit: note also that in this context, s-expressions are more about language and less about parentheses; one can have them in python too: http://wingolog.org/pub/original/rename-to-index.py.txt http://wingolog.org/pub/original/rename-to-index.py.txt, http://wingolog.org/software/original/ http://wingolog.org/software/original/
- mojuba 17y agoCan you easily filter raw text out of a Sexp stream? I don't think so. It would require a full Sexp machine to read and "understand" the tree, whereas with markup-style data streams it takes a trivial regexp to extract text. (Why would you need this? Search/indexing, for example.)
- gruseom 17y agoI don't understand. How would sexps be any worse than xml in terms of regexes? They're not that different from a parsing point of view (are they?) Besides which, regexes can't parse arbitrarily nested structures anyway.
- anamax 17y agoAn "sexp machine" is fairly simple. And yes, you can use regexs on s-expressions in exactly the same way that you'd use them on xml/html/markup. And you'd run into the same errors. Note that reading s-expressions and extracting things from the result is significantly easier and faster than using regexs.... (The same is true of xml.) Regular expressions are a great hammer, but many things are not nails.
- mojuba 17y agoWith XML or any markup you can ignore the hierarchy and easily strip out everything that's not text, while with Sexp's I'm afraid you can't. In order to extract raw text (or actually strings) from SXML you'd need to read and understand the tree structure, which is not possible with a single-regex run.
- anamax 17y agoOh really? How do you know that the sequence of bytes http://foo.bar.com/a/c http://foo.bar.com/a/c is text or an attribute value with a regexp? How about foo.bar? How about Times Roman or 16px? How about the four bytes html ?
- arethuza 17y agoIf by "raw text" you mean string values (i.e. the equivalent of text nodes in XML) I don't see this as being particularly difficult, I don't think I'd use a Regex for it but then I wouldn't use a Regex to extract text from an XML document/stream either.
- vdm 17y agoXML is not S-Expressions http://www.prescod.net/xml/sexprs.html http://www.prescod.net/xml/sexprs.html