CSC151.01 2015S, Class 20: Anonymous Procedures, Revisited
==========================================================

* New partners!

_Overview_

* Preliminaries.
    * Admin.
    * Upcoming Work.
    * Extra Credit.
    * Questions.
* Conditionals, Revisited.
* Anonymous Procedures, Revisited.
* Lab.
* Reflection.

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

### Admin

* Review session tonight at 7pm.
* I hope you had a great weekend and a great two days without me.
  I think I've caught up on all of the email questions I've received.
  If not, let me know.
* Office hours today at 11:00 a.m. and 3:15 p.m.  Office hours Tuesday
  at 10:00 a.m.  
    * <http://rebelsky.youcanbook.me>
    * Remember that if you invoked "There's More To Life" on the exam, 
      you need to meet with me.

### Upcoming Work

* [Homework 5](../assignments/assignment.05.html).
    * Due Tuesday at 10:30 p.m.
    * Note that 6P-style documentation is expected for every primary
      procedure you write.
* Lab writeup for today: Exercise 5, parts b-f,
  <http://bit.ly/151-2015S-lab20>
* Reading for Tuesday
    * [Local Bindings](../readings/local-bindings-reading.html)

### Extra Credit Opportunities

#### Academic 

* Pioneer Diversity Council Diversity Dialogue, 8:30 p.m. 26th, Main Quad
  "Academic Athletes and Academic Students".  *Note new date!*

#### Peer Support (Morning Section)

* Julia's radio show, "The Hot Box".  Wednesday night/Thursday morning 
  1:00-2:00 a.m.  
* Host a prospie.
* Neverland Players Friday and Saturday at 7:30, Sunday at 1:30 and 7:30
* Nobody Gets Hurt, a show with an audience of one.  Info on trying to
  get one of the tickets is on the posters.
* Indoor Track and Field Championships this weekend.

### Other Good Things

* ???

### Questions

_How do I copy and paste from images?_

    ;;; Procedure:
    ;;;   image-copy-paste-block!
    ;;; Parameters:
    ;;;   source, an image id
    ;;;   source-col, an integer
    ;;;   source-row, an integer
    ;;;   target, an image id
    ;;;   target-col, an integer
    ;;;   target-row, an integer
    ;;;   width, an integer
    ;;;   height, an integer
    ;;; Purpose:
    ;;;   Copy a width-by-height block from source to target, with the 
    ;;;   top-left corner of each block as specified.
    ;;; Produces:
    ;;;   [Nothing; called for the side effect.]
    ;;; Problems:
    ;;;   Does not do well with improper column/row pairs (e.g., those
    ;;;   outside the bounds of the image.

_I'm having trouble with problem 2.  Any hints?_

> Start by making sure you understand the problem, perhaps by working
  things through by hand.

    (visualize-transforms 
        (color->irgb "pink")
        (list (lambda (irgb-color) irgb-color)
              irgb-darker 
              (o irgb-darker irgb-darker)
              (o irgb-darker irgb-darker irgb-darker)
              (o irgb-darker irgb-darker irgb-darker irgb-darker))
         5)

> There are three parameters.  The first is a color.  (Is it an
  integer-encoded RGB color, a color name, or a list of the red/green/blue
  components or ...?)  Integer-encoded IRGB color.  Second is a list of 
  transformations.  What's a "transformation"?  It's a function from
  irgb values to irgb-values.  The 5 is the number of transformations
  you have.  (It's used as a parameter to visualize-colors, so we
  include it here for convenience.  The `length` procedure would also
  allow us to compute it.)

> Goal (for this call): Apply each of these five transformations to the 
  pink color, make a shape in each color, and show the five shapes.

    > (define c (color->irgb "pink"))
    > c
    16761035
    > (define t1 (lambda (irgb-color) irgb-color))
    > (t1 c)
    16761035
    > ((lambda (irgb-color) irgb-color) c)
    16761035
    > (define t2 irgb-darker)
    > (t2 c)
    15708347

> Now we are ready to put them in a list and then show them

        > (visualize-colors (list 16761035 15708347 ...) 5)

> Decompose problems.  You want to make a list of colors, and then 
  use `visualize-colors`.

> How do you make the list of colors?  Well, given a list of transformations
  of the form `'(t1 t2 t3 t4 t5)`, you want to make the list that contains
  the values `(t1 irgb-color)`, `(t2 irgb-color)`, `(t3 irgb-color)`,
  `(t4 irgb-color)`, and `(t5 irgb-color)`.  
  
> Given one list, you make another list with an appropriate call to `map`.
  Your challenge is to write that call.

_How do you write post-conditions for a procedure that returns a procedure?_

> Option 1:

    ;;; Produces:
    ;;;   proc, a procedure
    ;;; ...
    ;;; Postconditions:
    ;;;   proc has the form (proc param1 param2) where param1 is a
    ;;;   an integer and param2 is an image id.  proc computes ...

> Option 2:

    ;;; Produces:
    ;;;   proc, a procedure from integers and image ids to image ids.
    ;;; ...
    ;;; Postconditions:
    ;;;   (proc param1 param2) has the value ...

> Option 3:

    ;;; Produces:
    ;;;   proc, a procedure
    ;;; ...
    ;;; Postconditions:
    ;;;   proc meets the following specifications
    ;;;     Parameters:
    ;;;       param1, an integer
    ;;;       param2, an image id
    ;;;     Purpose:
    ;;;       ...
    ;;;     Produces:
    ;;;       image, an image id
    ;;;     Preconditions:
    ;;;       [No additional]
    ;;;     Postconditions:
    ;;;        ...

_In Problem 4 on Assignment 5, does "a simple shape of your choice" mean that the user can customize a shape, or that the programmer decides what shape to use?_

> I was assuming that you, in implementing the procedure, would decide what 
  the shape would be.

Conditionals, Revisited
-----------------------

You learned three new mechanisms for conditional evaluation:
`if`, `when`, and `cond`.  What are the similarities and differences
between them?  Why might you use one over another?

* `if` is when you have one condition and you want to choose between
  two options.
* `cond` is when you have multiple conditions
* `when` is for when you have one condition and no alternative if
  the condition doesn't hold (that is, you don't want to do anything
  if the condition doesn't hold)
* They have slightly different syntax/number of parameters
* In `if`, the options can only be a single expression; in `when` and
  `cond`, the options can be multiple expressions, which are evaluated
  in turn.

Many Scheme programmers consider `and` and `or` additional mechanisms
for conditional evaluation.  Why?

Anonymous Procedures, Revisited
-------------------------------

The reading was intended partially as review and partially to introduce
new ideas.  What new things did you learn about anonymous procedures?
