Search code examples
xmllispracket

Should I send X-expressions over the wire, or should I compile down to XML


I'm writing a program that will send something similar-ish to HTML over the internet. The way my program represents the data is through X-expressions.

Should I send the raw X-expression over the wire, or should I convert it to XML and then send? Do I lose any fidelity from going from one structure to the other?


Solution

  • In addition to the answers given as comments by Barmar:

    you can use the built-in read function

    and especially by Kaz:

    There can be a great benefit, because S-expressions preserve type information. They distinguish lists from vectors, strings from characters from symbols, from numbers; floating point from integer. Some Lisps have a circle notation so that graph structures can be serialized. XML is just chopped up, nested text with no meaning. JSON has only strings, floating-point numbers, vectors, dictionaries ("objects")., and a few symbols like true, false and none.

    you also have the option to use the racket/fasl binary format to transmit S-expressions. It offers faster loading and smaller size than write and read, at the cost of not being directly human-readable.