Tutorial by Examples

A pair can be create with the cons function. The name of the function stand for constructor. In Scheme, everything is pretty much based on pairs. (cons a b) The function return a pair containing the element a and b. The first parameter of cons is called car (Content Address Register) and the sec...
The data in the pair can be accessed with utility functions. To access the car, we have to use the car function. (car (cons a b)) > a Also we can verify the following equality: (eq? a (car (cons a b))) > #t
To access the cdr, we have to use the cdr function. (cdr (cons a b)) b Also we can verify the following equality: (eq? b (cdr (cons a b))) #t
List in scheme are nothing else than a series of pairs nested in each other in the cdr of a cons. And the last cdr of a proper list is the empty list '(). To create the list (1 2 3 4), we'd have something like this: (cons 4 '()) > (4) (cons 3 (cons 4 '())) > (3 4) (cons 2 (cons 3 (cons 4...

Page 1 of 1