|[ << Scheme tutorial ]||[Top][Contents][Index]||[ Interfaces for programmers >> ]|
|[ < Scheme compound data types ]||[ Up : Scheme compound data types ]||[ Lists > ]|
The foundational compound data type of Scheme is the
might be expected from its name, a pair is two values glued together.
The operator used to form a pair is called
guile> (cons 4 5) (4 . 5) guile>
Note that the pair is displayed as two items surrounded by
parentheses and separated by whitespace, a period (
more whitespace. The period is not a decimal point, but
rather an indicator of the pair.
Pairs can also be entered as literal values by preceding them with a single quote character.
guile> '(4 . 5) (4 . 5) guile>
The two elements of a pair may be any valid Scheme value:
guile> (cons #t #f) (#t . #f) guile> '("blah-blah" . 3.1415926535) ("blah-blah" . 3.1415926535) guile>
The first and second elements of the pair can be accessed by the
guile> (define mypair (cons 123 "hello there") … ) guile> (car mypair) 123 guile> (cdr mypair) "hello there" guile>
cdr is pronounced "could-er", according Sussman and