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
When will we get grades on homework assignments?
By Sunday evening.
Approximately seven things that we expect to see in algorithms
What kinds of repetition have we seen?
map: Takes a function and at least one list and applies the function
to each element (or groups of elements) - returns a listimage-variant: Takes as input an RGB transformation and an image
and applies the transformation to each pixel - returns an imagemake-list makes a list of a particular lengthimage-compute returns a computed image by applying a function at
each position.How do we do other kinds of repetition? In Scheme, with recursion.
car and cdr the list
To count the number of items in a list
Otherwise, it's 0
(define length
(lambda (lst)
(if (not (null?))
(+ 1 (length (cdr lst)))
0)))
Heaviest item in the list
Otherwise
Return the heavier of the two
(define heaviest (lambda (lst) (if (= (length lst) 1) (car lst) (heavier (car lst) (heaviest (cdr lst))))))
(define redder (lambda (color1 color2) (if (> (irgb-red color1) (irgb-red color2)) color1 color2)))
(define reddest (lambda (lst) (if (= (length lst) 1) (car lst) (redder (car lst) (reddest (cdr lst))))))
All the red items