lists
a common pattern
- (cons 1 (cons 2 (cons 3 nil))) creates a “list” of three elements:
-
-
-
-
-
-
-
- interpreter prints value as (1 2 3)
- don’t confuse with the Scheme expression (1 2 3), which fails to evaluate
list procedures
- nil or (), the empty list, is a special object
- (null? p) evals to #t when p is the empty list
- list makes a list from a sequence of values
(list 1 2 (+ 2 1)) –> (1 2 3)
- append makes a new list from two lists
(append (list 1 2) (list 3 4)) –> (1 2 3 4)