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

* New partners!
* Be prepared to shuffle around; we had too many cards.

_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 3:30 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!*
* CS Table Friday: Art and CS

#### Peer Support (Afternoon Section)

* Indoor Track and Field Conference

### Other Good Things

* Host a prospie.
* Neverland players this weekend

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

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

> Identify parameters: 1. Integer-encoded RGB color; 2. List of procs.
  "transformations" - given a color, produce a (potentially) new color.
  3. The number of transformations.

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

> `(map ______ transformations)`.

_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?

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?

Lab
---

* Yes, you can use `l-s` within compose.
