Next: , Previous: , Up: scheme lex datum   [Index]


3.4.4.2 Pairs and lists

List and pair data, representing pairs and lists of values are represented using parentheses or brackets. Matching pairs of brackets that occur in the rules of ?list are equivalent to matching pairs of parentheses.

The most general notation for Scheme pairs as syntactic data is the “dotted” notation (?datum1 . ?datum2) where ?datum1 is the representation of the value of the car field and ?datum2 is the representation of the value of the cdr field. For example (4 . 5) is a pair whose car is 4 and whose cdr is 5.

A more streamlined notation can be used for lists: the elements of the list are simply enclosed in parentheses and separated by spaces. The empty list is represented by ( ). For example,

(a b c d e)

and:

(a . (b . (c . (d . (e . ())))))

are equivalent notations for a list of symbols.

The general rule is that, if a dot is followed by an open parenthesis, the dot, open parenthesis, and matching closing parenthesis can be omitted in the external representation.

The sequence of characters (4 . 5) is the external representation of a pair, not an expression that evaluates to a pair. Similarly, the sequence of characters (+ 2 6) is not an external representation of the integer 8, even though it is an expression (in the language of the (rnrs base (6)) library) evaluating to the integer 8; rather, it is a syntactic datum representing a three–element list, the elements of which are the symbol + and the integers 2 and 6.


Next: , Previous: , Up: scheme lex datum   [Index]