Functional Problem Solving (CSC 151 2014F) : EBoards

CSC151.01 2014F, Class 28: Other Forms of List Recursion


Overview

Preliminaries

Admin

Upcoming Work

Cool Events

Extra Credit Opportunities

Academic

Peer Support

A Quick Note/Demo on Indentation

Comments on Academic Honesty

Questions (Administrative)

Questions and answers

Lab

What's the base case for largest?

It's easy to find the largest value in a single-element list. It's hard to find the largest value in a zero-element list.

I heard the mentors say "Oh, that's a different largest than I expected". What are the different ways that people write largest?

    (define largest-a
      (lambda (lst)
        (if (null? (cdr lst))
            (car lst)
            (max (car lst) (largest (cdr lst))))))

    (define largest-b
      (lambda (lst)
        (largest-b-helper (car lst) (cdr lst))))

    (define largest-b-helper
      (lambda (largest-so-far remaining)
        (if (null? remaining)
            largest-so-far
            (largest-b-helper (max largest-so-far (car remaining))
                              (cdr remaining)))))

I want to locally bind a non-recursive procedure called irgb-darker so that I can apply the pattern from problem 3.

Certainly

    (define irgb-darkest
      (let ([irgb-darker (lambda (color1 color2)
                           (if (> (irgb-brightness color1)
                                  (irgb-brightness color2))
                               color1
                               color2))])
        (lambda (colors)
          ...)))