XML is a cheap DSL

18 points by dz4k


jclulow

I am increasingly fond of KDL, which has the richness of the XML document model with a modern, ergonomic take on the actual markup structure.

jfred

I'm glad the post brought up s-expressions near the end, because - yeah, that's a lot more readable to my eye than the XML version.

It's worth noting that even if you are using XML, you can still use s-expressions! There's a nice thing called SXML that provides an alternative syntax for writing XML via s-expressions.

Here's what it can look like to work with that in Guile (the Lisp I happen to be most familiar with):

(use-modules (sxml simple))

(define fact
  '(Fact (@ (path "/tentativeTaxNetNonRefundableCredits"))
         (Description
          "Total tentative tax after applying non-refundable credits,
but before applying refundable credits.")
         (Derived
          (GreaterOf
           (Dollar 0)
           (Subtract
            (Minuend
             (Dependency (@ (path "/totalTentativeTax"))))
            (Subtrahends
             (Dependency (@ (path "/totalNonRefundableCredits")))))))))

(display
 (sxml->xml fact))

The @ character for setting attributes makes it a bit less ergonomic than the s-expression example given in the post, but the plus side (given that there's existing software that expects the XML) is that this is equivalent to the XML definition. This program prints the XML version of the s-expression Fact block to stdout.

I write Lisp in my off time so I quite like the above, but if you prefer fewer parentheses there's also a whitespace-sensitive syntax:

use-modules
  sxml simple

define fact
  quote
    Fact (@ (path "/tentativeTaxNetNonRefundableCredits"))
      Description
        "Total tentative tax after applying non-refundable credits,
        but before applying refundable credits."
      Derived
        GreaterOf
          Dollar 0
          Subtract
            Minuend
              Dependency (@ (path "/totalTentativeTax"))
            Subtrahends
              Dependency (@ (path "/totalNonRefundableCredits"))

display
  sxml->xml fact
bitslayer

I try to avoid XML, but I learned to respect it after I read this article. I have returned to it many times over the years; I find it mind expanding. It connects XML with Lisps, via the ANT build tool.

indolering

I miss declarative markup. When WHATWG broke off, they specifically endorsed that most logic should be declarative and then went all in on JavaScript instead.

I really do wish there had been a competitive process for XML instead of design-by-committee. The syntax, attributes, lack of arrays, and all the parsing weirdness ... it's just terrible to work with. At least we got comments (unlike JSON)!