CSC151.01 2014F, Class 36: Trees
================================

*New partners!*
   * Grab a card.
   * Read it, figure out where you go.
   * Put the card on the plate so that Evan doesn't have to collect it.

_Overview_

* Preliminaries.
    * Admin.
    * Upcoming Work.
    * Extra Credit.
* Questions/Ideas.
* Four kinds of repetition.
* Lab.
* Debrief.  (If time.)

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

### Admin

* Extended/modified office hours continue this week and next.
    * Survey: Should I switch to online signup for office hours?
      (Choices are "Please have online signup" and "Please keep
      physical signup".  You may also choose not to vote.)
* I've been answering a variety of prereg questions.  Feel free to 
  continue asking such questions.
* I apologize for missing much of class yesterday.  It was an emergency.
* I hear from some of the tutors that some of you are letting your partners
  carry the weight in your groups.  Doing so violates self-gov.
* Review sessions
    * Tonight at 8pm with Alex
    * Tomorrow at 10am with Sam
    * Tomorrow at 8pm with Ajuna
* A great quote from _Made to Stick_: "Trying to solve a problem
  *beore being taught the solution* leads to better learning, even when
  errors are made in the attempt."

### Upcoming Work

* Lab writeup: Problems 2 and 4a.  <http://bit.ly/151-2014F-w36>
* Reading for Friday: 
  [Geometric Art](../readings/geometric-art-reading.html)
* [Exam 3](../assignments/exam.03.html), distributed today, due next Tuesday.
    * *Required* prologue due Friday night. 
      <http://bit.ly/151-2014F-exam3pro>
    * *Required* epilogue due next Wednesday night.
      <http://bit.ly/151-2014F-exam3epi>
* Quiz Friday
    * Turtles
    * Iteration
    * Pairs and pair structures
    * You may bring a sheet of notes

### Cool Upcoming Events on Campus 

* Peace studies talk Monday Nov. 10 at 4:15 p.m. in JRC 101 
  "With All the World’s Violence, Where is Peace?"

### Extra Credit Opportunities

#### Academic

* CS Extra Thursday: Study-Abroad Opportunities with a CS Component
  4:30 p.m., Science 3821.
    * It's never too early to think about studying abroad!
* CS Table Friday: Open Data.
  12:10-12:50, Day PDR.

#### Peer Support

* Karan's radio show 11pm Thursday nights on KDIC
* Evan's radio show 5pm Friday nights on KDIC
* Donna's radio show Sunday midnight on KDIC
* Swimming on Saturday (1pm) against Luther.
* The gaming club is hosting a Smash Brothers tournament on Saturday
  (Loose at 11am ...) (And thats "Loose", not "Lose")
* The Go Club is having its first meeting Sunday 1pm, JRC 203
    * Aimed for complete beginners.

Questions/Recent Ideas/Etc.
---------------------------

_When do you use basic recursion and when do you use helper recursion?_

> Husk-and-kernel does one kind of helper recursion, but I think you 
  mean the question more generally.

> No general answer (at least not one that I know of).  It's mostly 
  which way makes it easier to think about solving the particular
  problem.

> If I find it "natural" to have one or more extra values during your
  recursion, I start with helper.

> I often end up writing whichever feels easier, and then go back and
  reflect on whether I might improve.

> Looking at/remembering similar kinds of problems helps.

_How do we write `listp?`_

> A list is either the empty list (i.e., `null `) or a pair whose cdr
  is a list.

        (define listp?
          (lambda (val)
            (or (null? val)
                (and (pair? val)
                     (listp? (cdr val))))))

_Is the null list a pair?_

> No, it is the only list that is not a pair.

Four Kinds of Repetition
------------------------

What's the relationship between the four kinds of somewhat general
repetition?  (`for-each`, `map`, `repeat`, recursion)`

* Take two minutes to talk to your partner about this question.
    * Identify similarites between pairs (or groups)
    * Identify differences between pairs (or groups)
* Be prepared to share.
* Things you might think about
    * Input types
    * Output types
    * Side effects vs. pure

Things we came up with

* Both `for-each` and `map` apply a function to every element in a list
    * map: Goal is to produce a new list
    * for-each: Goal is to have lots of side effects
* repeat does one procedure over and over again
    * With recursion, you do something over and over again
    * Repeat is a fixed number of times
    * recursion uses some "base case test", may be less predictable
* for-each and map do the application once to each element,
    * repeat does it multiple times to the same element
    * recursion could do anything (once, multiple times, no times, ...)
* (repeat 3 proc val) means do it three times
    * while recursion means doing one single function
* Input is a list
    * map, recursion, for-each (not repeat)
* Input is a number (or other non-list)
    * repeat, recursion (not for-each or map)
* Goal is side effects, rather than computing a value
    * repeat or for-each (or maybe recursion, but not map)
* Goal is to produce a list
    * map  - if the result is the same length, and fits the model
    * recurision - otherwise

Lab
---

Debrief
-------
