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