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
if.when.cond.What's the relationship between a Boolean and a conditional? Where does the Boolean part come in?
A Boolean is a truth value. True or False.
Scheme takes a slightly different view, False or "not False" "Not false" includes true, but also 45, "hello", "not false", drawing-unit-circle, ...
Procedures that assess some chacteristic of values are called predicatees (return true/false, or ??/false)
(define NAME lambda (PARAMETERS) BODY)(define NAME VALUE)We need to be able to sequence operations, implicitly or explicitly
Exact: In the body a procedure, if we have one expression, then another, then another, they are evaluated in sequence.
(define image-quincunx! (lambda (image color) (image-set-pixel! image 0 0 color) (image-set-pixel! image (+ -1 (image-width image)) 0 color)
mapimage-transform! or image-variantif, when, and condif or cond? If not, use whenwhen or cond.cond (or
nested if statements).Two ways to write irgb-brighter?
(define irgb-brighter?
(lambda (color1 color2)
(if (> (rgb-brightness color1) (rgb-brightness color2))
#t
#f)))
vs.
(define irgb-brighter?
(lambda (color1 color2)
(> (rgb-brightness color1) (rgb-brightness color2))))
Two ways to write irgb-grey4 with if?
(define irgb-grey4
(lambda (color)
(if (< (irgb-brightness color) 0.25)
grey1
(if (and (< (irgb-brightness color) 0.5)
(>= (irgb-brightness color) 0.25))
grey2
...))))
vs.
(define irgb-grey4
(lambda (color)
(if (< (irgb-brightness color) 0.25)
grey1
(if (< (irgb-brightness color) 0.5)
grey2
...))))