Functional Problem Solving (CSC 151 2014F) : EBoards

CSC151.01 2014F, Class 19: Conditionals


Overview

Preliminaries

Admin

Upcoming Work

Fun Things with no Extra Credit Value

Extra Credit Opportunities

Academic

Peer Support

Miscellaneous

Questions

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)

The parts of an algorithm, revisited

if, when, and cond

Comparing approaches

Lab

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
            ...))))