Functional Problem Solving (CSC 151 2015S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] - [Calendar]
Current: [Assignment] [EBoard am] [EBoard pm] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards am] [EBoards pm] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014F)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Book Office Hours] - [Issue Tracker (Course)]
Overview
let.'" (Conversation simulated.)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)