CSC151.01 2014F, Class 19: Conditionals
=======================================

* New Partners!

_Overview_

* Preliminaries.
    * Admin.
    * Upcoming Work.
    * Extra Credit.
    * Questions.
* The parts of an algorithm, revisited.
* Choosing between two options with `if`.
* Optional evaluation with `when`.
* Making multiple choices with `cond`.
* Comparing approaches.
* Lab.

Preliminaries
-------------

### Admin

* Epilogue for exam 1: <151-2014F-exam1epi>
* I've been reflecting a bit on the "vocabulary" you need for our quizzes.
  On one hand, I think you do much better if you memorize what the procedures
  are and what they do.  On the other, I know that such memorization can be
  quite difficult.  Hence, as an experiment on this Friday's quiz, I will 
  allow you to bring one page of notes to the quiz.  (8.5x11 or A4,
  double sided, hand written)
* Office hours (modified due to meetings): 
    * Wednesday 8:00-9:45
    * Thursday 8:00-9:45, 2:30-3:15
    * Friday 1:45-3:15 (also Walking hours 1:15-1:45)
* Review sessions 8pm Wednesday and Thursday.
* Let me know by 5pm today if you want to work alone on the next HW.
* I've had a student indicate that they will not be able to start HW 5
  until late Sunday afternoon and that they want partners for the HW.
    * Please fill out HW 5 partners form: <http://bit.ly/151-2014F-partners5>
* To provide you with incentive to take your own notes on each topic we
  cover: If you send me a summary of what you think are the important
  takeaways from any reading/lab combination, I will comment on your summary.

### Upcoming Work

* [HW 4](../assignments/assignment.04.html) due tonight.
* HW 5 to be assigned tomorrow.
* Lab writeup: Conditionals, 3c and 4d <http://bit.ly/151-2014F-w19>
  Due Friday!
* Reading for Wednesday
    * [Anonymous Procedures](../readings/anonymous-procedures-reading.html)

### Fun Things with no Extra Credit Value

* GHS Homecoming Parade Thursday at 5:30 pm.  (Small town Iowa homecoming
  is a fascinating experience.)
* Friends of Drake Library Book Sale, Friday night and Saturday.  At
  about 11 am on Saturday, you can get a box of books for a buck.  
  (Earlier, it's 50 cents for paperbacks and $1 for hardcovers.)

### Extra Credit Opportunities

#### Academic

* Campus Town Hall TODAY at noon or 7:30 p.m.
* CS extras next Thursday: Alumni
* CS table Friday: Serendipity and Computing (with Grinnell's Artist 
  in Residence)
* Grinnell Prize events the following week (particularly events related
  to the prize winners whose project involves Web tools)

#### Peer Support

* Wednesday night's [Concerts]
* Anna Christie, Oct. 9-12 (SB plays Marthy)
* Football (???)
* Men's Tennis (???)
* Women's Tennis (???)
* Swimming (???)
* Evan's radio show 5pm Friday nights on KDIC
* Donna's radio show Sunday midnight on KDIC

#### 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
------------------------------------

* We need to be able to write subroutines/procedures
    * Parameters
    * Instructions
    * `(define NAME lambda (PARAMETERS) BODY)`
* We need to be able to name values ("Variables")
    * `(define NAME VALUE)`
* We need to be able to sequence operations, implicitly or explicitly
    * Approximate: Nesting.  Inner expression gets evaluated first.
      But if the outer expression has multiple inner expressions, they
      can be evaluated in any order.
    * 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)
    * Clever use of lambda can also achieve some control of sequence
* We need to be able to repeat operations 
    * Fixed number of times
    * Until a goal is achieved
    * `map`
    * `image-transform!` or `image-variant`
    * We will learn more general approaches next week
* We need a set of basic operations and values
    * Numbers and numeric operations
    * Images and their operations
    * Drawings and their operations
* We need to be able to make choices

`if`, `when`, and `cond`
------------------------

* See the start of lab.

Comparing approaches
--------------------

* Do you have an alernative?  Use `if` or `cond`?  If not, use `when`
* Do you want to do more than one thing if a test holds?  If so,
  use `when` or `cond`.
* Do you have multiple tests to do in sequence?  If so, use `cond` (or
  nested `if` statements).

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

