A report from OpenSQLCamp
A report from OpenSQLCamp
Posted Nov 10, 2010 21:59 UTC (Wed) by nix (subscriber, #2304)In reply to: A report from OpenSQLCamp by jeremiah
Parent article: A report from OpenSQLCamp
(Has anyone written an XML -> sexp bidirectional filter? If not, I should: it wouldn't be hard and would make this stuff *so* much easier for humans to read and write. It's quite an achievement, actually, coming up with something *less* readable than Lisp's sexps... the SGML/XML people should be proud.)
Posted Nov 10, 2010 23:40 UTC (Wed)
by jeremiah (subscriber, #1221)
[Link] (4 responses)
I deal with XML every day, and agree with the verbosity and ugliness comment. The only way i can make it palatable is lots of indenting, and syntax highlighting, and even then it's pretty rough some times. I like it's flexibility and ubiquitousness though. I don't hate it nearly as much as I dislike the SQL language.
Posted Nov 11, 2010 0:11 UTC (Thu)
by nix (subscriber, #2304)
[Link] (3 responses)
<foo bar="baz">quux<wob>foo</wob>blah</foo>
you could say
(foo :bar "baz" (:content "quux" (wob (:content "foo")) (:content "blah")))
perhaps. Or, if you don't like the ":content", you could say
(foo (:attr bar "baz") "quux" (wob "foo") "blah")
(yeah, I think the latter is much easier to read. Attributes are less common than content in decent XML, so attributes should be more verbose in the sexpy syntax.)
Note that both these syntaxes render it impossible to close elements in the wrong order and impossible to do the analogue of missing a / out. Those two things on their own make it worthwhile, I think.
(I am by no means the first person to have thought about this. I'm not even the five thousandth.)
Posted Nov 11, 2010 1:13 UTC (Thu)
by jeremiah (subscriber, #1221)
[Link] (2 responses)
Posted Nov 11, 2010 2:11 UTC (Thu)
by jeremiah (subscriber, #1221)
[Link]
Posted Nov 11, 2010 7:17 UTC (Thu)
by nix (subscriber, #2304)
[Link]
Note: a nice thing about using a real programming language rather than XML is that you could go the whole hog if you want and eliminate redundancy, although this looks uglier than it should because all my indentation is being eaten by the comment form and because I've only got one line of XML generated, much too little to be worth using this technique:
(let ((type-string '(:attr type "string"))
is equivalent to
<foo type="string">quux<num-foos type="int">6</num-foos></foo>
If you wanted to have 'type's with parameters, let alone optional ones, you'd have to do something a little different:
(flet ((type-float (precision) `(:attr type "float" `(:attr type ,(concat "float-" ,precision)))))
is equivalent to
<foo type="float-6">14.172</foo>
Note that the latter is horribly hard to typecheck properly in XML, but having something typecheck the Lisp notation is trivial. Also note that your generator and parser don't need to understand Lisp (although it is so easy the parser might as well understand a restricted subset): it just needs to know how to generate stereotyped let and (for parameterized attributes) flet expressions.
A report from OpenSQLCamp
A report from OpenSQLCamp
A report from OpenSQLCamp
A report from OpenSQLCamp
A report from OpenSQLCamp
(type-int '(:attr type "int")))
(foo type-string "quux" (num-foos type-int 6)))
(foo (type-float 6) 14.172))