In a 2012 Dr. Dobb’s retrospective, Karl Eiger noted that S-expressions are have been in continuous use longer than any other formats that remain in widespread use today.
A variety of structures like hash tables can be serialized as basic lists or as a list of dotted-pair cons cells.
Values:
truefalse
Nil is traditionally encoded as the empty list (()), however this can lead
to problems in structures which need to serialize fields like
Option<Vec<T>>, where both None and Some([]) will serialize to the
empty list.
Possible values:
empty_list()hash#nilnulnul
*)) Types
let ht = HashMap::new();
ht.insert("APPLES", 1);
ht.insert("ORANGE", 2);
ht.insert("STRAWBERRIES", 3);((APPLES 1) (ORANGES 2) (STRAWBERRIES 3)) ((APPLES . 1) (ORANGES . 2) (STRAWBERRIES . 3))
((variant HashMap) ((APPLES 1) (ORANGES 2) (STRAWBERRIES 3)))
(dict ((APPLES 1)
(ORANGES 2)
(STRAWBERRIES 3)))
((:APPLES 1 :ORANGES 2 :STRAWBERRIES 3))
struct Color {
r: u8,
g: u8,
b: u8,
}
Color { r: 254, g: 1, b: 10 }((r 254) (g 1) (b 10))
((variant Color) ((r 254) (g 1) (b 10)))
(Color :r 254 :g 1 :b 10)
struct Foo {
x: Option<isize>
}
Foo { x: None }
Foo { x: Some(5) }The representation of #nil can be configured.
((x 5)) ((x #nil))
((variant Foo) (x None)) ((variant Foo) (x 5))
(1,2,3)(1 2 3)
((_field0 1) (_field1 2) (_field2 3))
&[41, 41, 19, 1](41 41 19 1)
#(41 41 19 1)