… and cons’ing up
(list of int) –> (list of int)
- procedure that adds one to each element in a list*
(define (add1p) (if (null? p) nil (cons (inc (car p)) (add1 (cdr p))))
-
- procedure that squares each element in a list
(define (square-each p) (if (null? p) nil (cons (square (car p)) (square-each (cdr p))))
-
* note sloppy language: the list does not change! we should really say“creates a new list whose elements are one more than the correspondingelements of the old list”.