4 ms·
The usefulness of having a common structure for which to build types is that you can break them down from code into smaller types, or combine them into larger t
by sparkie 8y ago
The usefulness of having a common structure for which to build types is that you can break them down from code into smaller types, or combine them into larger types, using just the functions `cons`, `car` and `cdr`. This is particularly useful for working on tooling which deals with the programming language code itself.
A pair is just the most basic kind of compound data type. A triplet is just an atom plus a pair, and a quadruplet is an atom plus a triplet, and so forth. For any data structure containing N items, it can be represented as a sequence of N-1 cells.
It's possible to map this to custom data types. Say you wanted a type of `vec {x, y, z}`, then you can represent it as a list `(x (y (z . ())))` where you could define `get-x = car`, `get-y = cadr` and `get-z = caddr` to access the elements by name. Some lisps let you encapsulate the result such that only those functions can be used on the encapsulated list.
Rather then being more powerful to build everything into a language, it actually makes it less powerful when you try to do everything rather than providing the foundations on which other types can be built. See also: "Growing a language" by Guy Steele.