;;; *************************************************** ;;; procedure sum-n takes integer n >= 0 as input and ;;; returns the sum of the numbers up to and including n. ;;; (define (sum-n n) (cond ((zero? n) 0) (else (+ n (sum-n (- n 1)))) ) ) ;;; *************************************************** ;;; procedure length takes a list as input and returns ;;; its length. ;;; (define (length x) (cond ((null? x) 0) (else (+ 1 (length (cdr x)))) ) ) ;;; *************************************************** ;;; procedure abs-list takes a list of numbers as input ;;; and returns a list containing the absolute value of each ;;; number in the list. ;;; (Note this is not an efficient implementation. Why?) (define (abs-list l1) (cond ((null? l1) '()) (else (cons (if (> 0 (car l1)) (- (car l1)) (car l1)) (abs-list (cdr l1)))) ) ) ;;; *************************************************** ;;; procedure append takes two lists as input and returns ;;; one list that is the second list appended to the first ;;; (define (append l1 l2) (if (null? l1) l2 (cons (car l1) (append (cdr l1) l2)) ) )