2  Monday Afternoon: Images, Lists, N

Related material in How to Design Programs: intermezzo 2, part II[11]

2.1  Goals

(1) to make working with lists and S-expressions easier

(2) to get to know the class of image values

(3) to understand functions on natural numbers

2.2  A Notation for Lists


(cons 1
  (cons 2
    (cons 3 empty)))

(list 1 2 3)


(cons
  (cons 'a (cons 'b empty))
  (cons
    (cons 1 (cons 2 empty))
    (cons
      (cons true (cons false empty))
      (cons
	(cons "a" (cons "b" empty))
	empty))))

(list (list 'a 'b)
      (list 1 2)
      (list true false)
      (list "a" "b"))


(cons (make-color 0 0 0)
  (cons (make-color 255 255 255)
    (cons (make-color 200 100 0)
      empty)))

(list (make-color 0 0 0)
      (make-color 255 255 255)
      (make-color 200 100 0))