CSC151.01 2014F, Class 20: Anonymous Procedures
===============================================

* Keep your partners from yesterday.*

_Overview_

* Preliminaries.
    * Admin.
    * Upcoming Work.
    * Extra Credit.
    * Questions.
* A quick note on HW 4
* A few notes on yesterday's lab
* Questions on the reading 
    * From you
    * From me
* Lab

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

### Admin

* Office hours (modified due to way too many meetings): 
    * Thursday 8:00-9:45, 2:30-3:15
    * Friday 2:15-3:15 
* Review session Thursday at 10:00 a.m.
* Review sessions Wednesday and Thursday night at 8 p.m.

### Upcoming Work

* [HW 5](../assignments/assignment.05.html) assigned.
* No lab writeup from today.
* Reading for Friday:
    * [Local Bindings](../readings/let-reading.html)

### Quiz Topics

*Reminder: You may bring a sheet of notes to Friday's quiz.*

* Lists (using `list`, `make-list`, and `iota`)
* `map`
* More simple lambda expressions
* Conditionals
* GIMP procedures (e.g., `image-select-rectangle!`)
* `compose`, `o`, `l-s`, `r-s` (the latter two from today's class)

### Extra Credit Opportunities

#### Academic

* CS extras Thursday at 4:30: 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

* Concert tonight.
* 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
* Anna Christie, Oct. 9-12 (SB plays Marthy)

### Questions (Administrative, Recent Topics, Etc.)

Followup Notes from Tuesday
---------------------------

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

Multiple ways to write `irgb-4grey` with `if`?

    (define irgb-4grey
      (lambda (color)
        (if (< (irgb-brightness color) 0.25)
            grey1
            (if (and (< (irgb-brightness color) 0.5)
                     (>= (irgb-brightness color) 0.25))
                 grey2
                 (if (and (< (irgb-brightness color) 0.75)
                          (>= (irgb-brightness color) 0.5))
                      grey3
                      (if (and (<= (irb-brightness color 1.0))
                               (>= (irg-brigthness color 0.75)))
                           grey4
                           0))))))

vs.

    (define irgb-4grey
      (lambda (color)
        (if (< (irgb-brightness color) 0.25)
            grey1
            (if (and (< (irgb-brightness color) 0.5)
                     (>= (irgb-brightness color) 0.25))
                 grey2
                 (if (and (< (irgb-brightness color) 0.75)
                          (>= (irgb-brightness color) 0.5))
                      grey3
                      grey4)))))

vs.

    (define irgb-4grey
      (lambda (color)
        (if (<= (irgb-brightness color) 0.25)
            grey1
            (if (<= (irgb-brightness color) 0.5)
                grey2
                (if (<= (irgb-brightness color) 0.75)
                    grey3
                    grey4)))))

vs.

    (define brightness-4grey
      (lambda (brightness)
        (if (<= brightness 0.25)
            grey1
            (if (<= brightness 0.5)
                grey2
                (if (<= brightness  0.75)
                    grey3
                    grey4)))))
    (define color-4grey
      (lambda (color)
        (brightness-4grey (irgb-brightness (color->irgb color)))))

vs.

    (define irgb-4grey
      (lambda (color)
        (if (<= 0 (irgb->brightness color) 0.25)
            grey1
            (if (<= 0.25 (irgb-brightness color) 0.5)
                grey2
                (if (<= 0.5 (irgb-brightness color) 0.75)
                    grey3
                    grey4)))))

Followup to HW 4
----------------

    (define apply-transform
      (lambda (transform irgb-color)
        (transform irgb-color)))
   
    (define visualize-transforms
      (lambda (irgb-color list-of-transforms number-of-transforms)
        (visualize-colors (map apply-transform
                               list-of-transforms
                               (make-list number-of-transforms irgb-color))
                          number-of-transforms)))

vs.
    
    (define visualize-transforms
      (lambda (irgb-color list-of-transforms number-of-transforms)
        (visualize-colors (map (lambda (trans) (trans irgb-color))
                               list-of-transforms)
                          number-of-transforms)))

Your Questions on the Reading
-----------------------------

_What's the point of `l-s` and `r-s`?_

> Lets you write shorter (and more readable?) code

        (map (l-s * 2) (iota 5))
        (map (lambda (x) (* 2 x)) (iota 5))

_What do left section and right section do?_

> Fill in one of the parameters for a two-parameter procedure.

> left-section fills in the first parameter. right-section fills in the second

        > (map (l-s / 2) (iota 5))
        ; (map (lambda (val) (/ 2 val)) (iota 5))
        ; (list (/ 2 0) (/ 2 1) (/ 2 2) (/ 2 3) (/ 2 4))

        > (map (r-s / 2) (iota 5))
        ; (map (lambda (val) (/ val 2)) (iota 5))
        (list (/ 0 2) (/ 1 2) (/ 2 2) (/ 3 2) (/ 4 2))

_Can you explain this weird code? `(map (o increment (l-s * 2) (r-s mod 7)) (iota 50))`

> Start with

        > (map (o (r-s mod 7)) (iota 20))
        ; (map (lambda (x) (mod x 7)) '(0 ... 19))
        > (map (o (l-s * 2) (r-s mod 7)) (iota 20))
        ; (map (l-s * 2) '(0 1 2 3 4 5 6 0 1 2 3 4 5 6 ...))
        0 2 4 8 10 12 0 2 4 8 10

        > (map (o (r-s mod 7)) (iota 20))
        '(0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5)
        > (map (o (l-s * 2) (r-s mod 7)) (iota 20))
        '(0 2 4 6 8 10 12 0 2 4 6 8 10 12 0 2 4 6 8 10)
        > (map (o (l-s mod 7)) (iota 20))
        . . share/lib/gigls/higher.rkt:256:20: modulo: undefined for 0
        > (map (o (l-s mod 7)) (drop (iota 20) 1))
        '(0 1 1 3 2 1 0 7 7 7 7 7 7 7 7 7 7 7 7)
        > (map (o increment (l-s * 2) (r-s mod 7)) (iota 20))
        '(1 3 5 7 9 11 13 1 3 5 7 9 11 13 1 3 5 7 9 11)

My Questions on the Reading
---------------------------

*Discuss each of these with your partner and be prepared to answer.*

a. What is the difference between `(l-s + 2)` and `(r-s + 2)`? 

b. What is the difference between `(l-s - 2)` and `(r-s - 2)`? 

c. What is the difference between `(o increment sqrt)` and `(o sqrt increment)`?

Lab
---

For the extras, we want things like

        ; Compose f and g.  Return the function that, given an input
        ; x, applies g to x and then f to x.
        ; In math notation, (fog)(x) = f(g(x))
        (define my-compose
          (lambda (f g)
            (...)))
