CSC151.01 2015S, Class 34: Iteration
====================================

* New Partners!

_Overview_

* Preliminaries.
    * Admin.
    * Upcoming Work.
    * Extra Credit.
    * Questions.
* Lessons from yesterday's lab.
* A useful tool for repetition: `for-each`.
* Contrasting `map`, `for-each`, `repeat`, and recursion.
* Lab.

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

### Admin

* Review sessions Thursday at 9:15am (Sam), 1:15pm (Sam), and 8pm (Alex).
* After reflecting, I flipped the topics for today's class and Friday's class.
  Sorry!

### Upcoming Work

* Lab writeup!  Problems 8, 9, and 10.
  <http://bit.ly/151-2015S-lab34>
* Reading for Friday: 
    [Geometric Art](../readings/geometric-art-reading.html)
* Assignment 7 distributed: Producing Playful Polygons.

### Extra Credit Opportunities

#### Academic 

* Scholars Convocation.
* CS Table Friday: Therac 25 (readings coming soon)

#### Peer Support (Morning Section)

* Julia's radio show, "The Hot Box".  Wednesday night/Thursday morning 
  1:00-2:00 a.m.  
* Contact JMU to host a prospie.  You also get a good dinner in quad and
  the ability to attend an incredible improv show.  Sunday April 12th.
  Most importantly, you convince awesome people that they should come to
  Grinnell.
* KY's radio show, Mondays, 9-10pm, "At Least We Think We're Funny" 
* Baseball game Thursday at whatever time is on the campus calendar.

#### Miscellaneous

* Tonight's "Moving Forward" discussion.

### Other Good Things (no extra credit)

* 7:30 p.m. on April 2: Gender as a Process.  EE talks afterwards
  about using mathy things to understand gender.

### Exam 2 returned.

Strongest arguments

* "The main goal of the exams is that we learn.  We've learned.  Exam grades
   are likely to be relatively consistent across exams, so not counting this exam
   is unlikely to have an effect on students who did not get inappropriate help."
* "Many of us worked very hard on this exam and should see rewards for our
   hard work."
* "You should have a policy that does not discourage people from coming forward."

### Questions

Learning outcomes from yesterday's lab
---------------------------------------

* A few small tools and mechanisms for combining them give great opportunity.
* To use turtles successfully, you need to be able to determine where they are
  after each step (and, often, restore some characteristic).

A useful tool for repetition: `for-each`
----------------------------------------

* `for-each` is a variant of `map`.
     * `map` applies a function to every element of a list.
     * and produces a new list (each element of which is the result of applying
       the function)
* To make a spiral, we might have a list like '(1 2 3 4 5 6 7 ...)` and for each
  number, move forward that amount and turn 10 degrees
* If we used `map`, we'd end up with a useless list of turtles.
* `for-each` is just like `map`, except that it returns NOTHING
     * We call the functions for SIDE EFFECTS rather than to get a new value
    
Contrasting `map`, `for-each`, `repeat`, and recursion
------------------------------------------------------

    > (map (lambda (s) (display s) (newline))
           (list "Happy" "April" "Sam's" "Day"))
    Happy
    April
    Sam's
    Day
    '(#<void> #<void> #<void> #<void>)
    > (for-each (lambda (s) (display s) (newline))
                (list "Happy" "April" "Sam's" "Day"))
    Happy
    April
    Sam's
    Day
    > (repeat 4
              (lambda (s) (display s) (newline))
              (list "Happy" "April" "Sam's" "Day"))
    (Happy April Sam's Day)
    (Happy April Sam's Day)
    (Happy April Sam's Day)
    (Happy April Sam's Day)

Lab
---

* You can clear your image with "Select All" and then "Delete"

Some lessons

* Systematic procedures can produce very complex systematic images
* Systematic procedures can produce things that don't seem very systematic
  at all (e.g., things Erin would call "derpy")
* Serendipity!
* Build something more complex by repeating a simple action.  Then build something
  even more complex by repeating that repetition.  And so on and so forth.
