Upcoming Schedule

Using Map

Here's a complex example use of list-map in the choose-n procedure from PS2:
(define (choose-n n lst)
  ;; operands: a number n and a list (of at least n elements)
  ;; result: evaluates to a list of all possible was of choosing n
  elements from lst
  (if (= n 0) 
      (list null) 
      (if (= (list-length lst) n) 
          (list lst) ; must use all elements
            (choose-n n (cdr lst)) ;; all possibilities not using first element
            (list-map (lambda (clst) (cons (car lst) clst)) 
                             (choose-n (- n 1) (cdr lst)))))))
What is the list-map application expression doing?

(define (map2d f p) 


Generalizing List Procedures

(define (list-map f p)
    (if (null? p)
         (cons (f (car p))
                    (list-map f (cdr p)))))
(define (list-sum p) 
    (if (null? p)
        (+ (car p) (list-sum (cdr p)))))
(define (list-length p) 
    (if (null? p)
        (+ 1 (list-length (cdr p)))))
(define (is-list? p)
    (if (null? p) 
        (if (pair? p) (is-list? (cdr p)) false)))
(define (list-cruncher baseres carproc combiner p)
     (if (null? p) baseres
            (carproc (car p))
            (list-cruncher baseres carproc combiner (cdr p)))))

(define (list-sum p)

  (list-cruncher _____ ___________________  _____ p))

(define (list-map f p)

  (list-cruncher _______  ______   ______ p))

(define (list-length p)

  (list-cruncher ______  _____________ + p))
Is it possible to define is-list? using just list-cruncher?

How is list-cruncher similar and different from list-accumulate? (Section 5.4.2)

(define (list-accumulate f base p)
    (if (null? p) base
         (f (car p) (list-accumulate f base (cdr p)))))

Gold star bonus: Is there any procedure that can be defined using list-cruncher that cannot be defined using list-accumulate?