40 points · by todsacerdoti · 4y ago · 19 comments
https://okmij.org/ftp/Scheme/xml.html#SXML-spec
SXML is a little harder to process in libraries, compared to some representations we initially try, but SXML turns out to be easier to use in practice, at least by users of the library. For example, splices can be much more efficient, and easier to do without making a programming error that's not detected statically.
You can also mimic it in syntax, like:
It's not as ideal, but you can even get away with this in Python using comprehensions and functions. Any language with nested data structure literals will do. Really, any expression language.
Here's a Python version: https://github.com/dgoffredo/dgoffredo.github.io/blob/master...
and a Javascript version: https://github.com/dgoffredo/llama/blob/master/llama/xml.js
...and as others have said, Scheme has "sxml," which I use here: https://github.com/dgoffredo/xsd-gc
(1) Triple-quoted strings to set up large markup forms
(2) The `%()s` syntax to set up dictionary interpolations
(3) Something like:
def merge(template, args):
return template % args
to deliver the goods.[1]: https://reactjs.org/docs/introducing-jsx.html
[2]: https://github.com/phplang/xhp
[3]: https://docs.microsoft.com/dotnet/visual-basic/programming-g...
Here[1] is a fun example of what's possible with a Common Lisp library that would be difficult to do in many other languages without language changes or essentially just giving up and dumping the C style code in a string and calling some sort of eval on it. That is very much not the same thing.
In the version of English that I speak, “features unique to Lisp” does not mean “features that no language had prior to Lisp” or “features that were inspired by Lisp” but rather “features that no language other than Lisp has”.
[0]: https://github.com/askonomm/bruno (documentation pending, check out example site at https://github.com/askonomm/bien.ee)
[1]: https://github.com/askonomm/bien.ee/blob/master/src/feed.xml...
[2]: https://github.com/askonomm/bien.ee/blob/master/src/index.ht...
ELisp seems like going to the right direction but I'd like to hear more about logic-ful or logic-less, what should only be allowed in template, how context-free it is, etc.
ps; as someone who hate parsing stuff with passion. give me a format that's good enough for hand authoring programmable format. S-expression is close .. but not yet a great solution.
If you really like elisp maybe that is not a bad trade off.
[1]: https://practical.li/clojurescript/hiccup-style-syntax.html