英文:
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.
我正在编写一个程序,它将在互联网上传输类似于HTML的内容。我的程序通过X表达式来表示数据。
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?
我应该将原始的X表达式传输到网络上,还是应该将其转换为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?
答案1
得分: 1
除了由Barmar提供的评论中所给出的答案:
> 你可以使用内置的read
函数
以及特别是由Kaz提供的答案:
> 这是有很大好处的,因为S表达式保留了类型信息。它们区分了列表和向量,字符串和字符以及符号,还有数字;浮点数和整数。一些Lisp语言具有循环符号表示法,以便可以序列化图结构。XML只是切割、嵌套的文本,没有含义。JSON只有字符串、浮点数、向量、字典("对象")以及一些符号,如true
、false
和none
。
您还可以选择使用racket/fasl
二进制格式来传输S表达式。它具有比write
和read
更快的加载速度和更小的大小,但不能直接人类可读。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论