CSC151.02 2013F, Class 44: Higher-Order Procedures, Revisited
=============================================================

_Overview_

* Preliminaries.
    * Admin.
    * Updates on due dates.
    * Questions on the project.
* Big Picture Issues.
    * Some program design principles.
    * Thinking about repetition.
* Procedures as first-class values.
* What's the difference between apply, map, and for-each?
* Lab.

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

### Admin

* Pictures!
* Today's lab writeup (#26): Turn in 3, 4.
* I hope to get your project proposals reviewed by Thursday night.
* Upcoming extra credit opportunities:
    * Basketball tonight at 5:30 pm.
    * Seth performs at Relish tonight at 10pm.
    * CS Table, Friday, The New Curriculum.
    * Hamlet, Friday (7:30pm), Saturday (7:30pm), Sunday (2pm).
    * Swimming, Saturday, 10 am
    * Chamber Ensemble, Saturday, 7:30 pm.
    * Typhoon Halyan Relief benefit show, Sunday, November 24th from 
      7-9pm in Harris.  (If the entry fee is a burden, let me know 
      and I'll give you the money.)
    * "Data Sovreignty: The Challenge of Geolocating Data in the Cloud",
      November 25, 4:15 JRC 101
    * Showing of "Gold Fever" by Andrew Shurburne '01 or so, 7:00 p.m.
      Monday, November 25, ARH 302
    * Tuesday, November 26, 4:15 p.m., JRC 209  a gaming event with the 
      game [d0x3d!]   Popcorn will be served.

### Watch Sam Screw Up Due Dates

Planned (but not quite what was on the Web site)

* Project due Tuesday, November 25th
* Exam due Monday, December 9th

Revised

* Project due Tuesday, December 3rd
* Exam due Tuesday, December 10th
* 2 point bonus for turning in the exam on Monday, December 9th

### Questions

_Are subtle progressions ok?_

> Yes

_Can it be representational?_

> Yes

_Can it be representational and good?_

> Past evidence suggests no.

Some program design principles
------------------------------

* More efficient code is better.
   * Don't do a computation twice if you can do it once.
   * let is your friend
* Don't program by copy-paste-change
   * Mistake-prone
   * Hard to update!
   * Solution: Factor out the common parts
   * More efficient use of programmer time

Thinking about repetition
-------------------------

* See outline
* Once you understand a control structure, encapsulate it into
  something general, and use the general thing
* Example map

Procedures as first-class values
--------------------------------

* We can write procedures that take other procedures as parameters
    (e.g. map - apply a procedure to each value in a list)
* We can write procedures that create new procedures
    (e.g. l-s)
* Procedures are just another kind of value
* A new type!
    * How do we write them?
      (lambda (params) body)
    * How do we create values?
      compose, section, ...
    * What kinds of functions can we apply to the values we create?
      map, compose, section, apply

Some related proedures - apply vs. map
--------------------------------------

* apply: Given a procedure and a list, "applies the procedure to
  the list"
    * For map, we mean "apply the procedure to each element of the
      list separately"
    * For apply, we mean "take the elements of the list, and make
      them parameters for ONE procedure call."
* (apply + (list 1 2 3)) => (+ 1 2 3)
* (map + (list 1 2 3)) => (list (+ 1) (+ 2) (+ 3))

Lab
---
