Functional Problem Solving (CSC 151 2015S) : EBoards

CSC151.01 2015S, Class 32: Naming Local Procedures


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support (Afternoon Section)

Miscellaneous

Other Good Things

Notes on Exam 2

Questions

Lab

Given that the computation of brightness is 0.3*red + 0.59*green + 0.11*blue, why is red the brightest color?

> (irgb->string (color->irgb "red"))
"255/0/0"
> (irgb->string (color->irgb "green"))
"0/128/0"
> (irgb->string (color->irgb "blue"))
"0/0/255"

What should our solution to problem 2 look like?

(define irgb-brightest
  (letrec ([kernel (lambda (brightest-so-far remaining)
                     ...)])
    (lambda (colors)
      (cond
        [(null? colors)
         (error "irgb-brightness requires a non-empty list")]
        [(not (list? colors))
         (error "irgb-brightest expects a list, received" colors)]
        ...
        [else
         (kernel (car colors) (cdr colors))]))))

How do we check whether every element of a list is an irgb color?

Refer back to quiz 8.

Refer back to recursion with Booleans.

    (define all-____?
      (lambda (lst)
        (or (null? lst)
            (and (____? (car lst))
                 (all-____? (cdr lst))))))

(all irgb? colors)

Debrief

Debrief