Scheme Programming/Scheme Datatypes

Scheme has several datatypes, there are atomic datatypes and compound datatypes, the significant difference between both is that while atomic datatypes are unique and immutable, compound datatypes are mutable, this means that we can modify them. This also means that there can be for instance two different strings  even though they have the same characters, while every character   is the same object.

Booleans
Booleans are either  (true) or   (false). Booleans are self-evaluating.

Numbers
Numbers are self-evaluating, and are entered as expected. Scheme also supports complex numbers as for instance. Just typing  is interpreted as a symbol in Scheme, beware.

Characters
Characters are self-evaluating and entered as such.

Symbols
Symbols are sequences of characters, different from strings because they are not self-evaluating, and they can't contain white-space either. They are just input by typing them really, for instance  is a list in Scheme that contains three symbols.

Pairs and Lists
Pairs and lists are the most important compound types in Scheme. We already said that Scheme source code itself made up of lists, thus lists are obviously not self-evaluating. Typing a list which cannot be sensibly evaluated (such as one that starts with a number) will produce an error.

There is one list though which is atomic; it's called the empty list, or nil or null, depending to whom you talk. It's simply the list of no elements at all. It's represented in source code by.

All other lists are in effect pairs in disguise, a pair of a and b is written like, this is different from a list of a and b. Pairs are also not self-evaluating and often produce an error. What a list is, is just a pair, whose first element (also called its car) is the first element of the list, and whose second element (also called its cdr) is a list containing all the other elements. Thus the list:

Is just a shorthand for:

Vectors
The problem with lists is that list-ref and list-set! are slow operations if the list is very large. For a data structure that allows fast reading and writing, Scheme provides vectors.

Here is an example of a vector of numbers:

Strings
Strings are sequences of characters. They are contained by double-quotes.