CSC151.02 2016S, Class 31: Pause for Breath
===========================================

* No new partners because ST wanted to confuse everyone!
* Cover sheets!

_Overview_

* Preliminaries.
    * Admin.
    * Upcoming Work.
    * Extra Credit.
    * Questions.
* Why use helper recursion?
* Lab.

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

### Admin

* I'm back!
* Please don't use profanity in class.
* I checked with an older colleague.  While the term "kernel" has been
  commonly used for decades, the phrase "husk and kernel" is due to
  Grinnell faculty, and is not commonly used.
    * The same faculty member invented the word "termial"
* PSA.

### Reminders

* Office hours this week 
    * See http://rebelsky.youcanbook.me.
    * Ask me about other available times.
* Tutor hours
    * Sunday, 3-5 p.m.
    * Sunday-Thursday, 7-10 p.m.
* Weekly review sessions:
    * Wednesday at 8pm in the CS Commons with Sarah
    * Thursday 10 am review session with Samer.
    * Thursday at 8pm in the CS Commons with Kumar.

### Upcoming Work:

* Cover sheets due now!
    * Make sure that you've signed the two parts separately.
    * Make sure that you've dated your signature.
    * Make sure that you've included your number.
* Quiz Friday (or Thursday between 10:00 and 10:50) (or other
  arranged time in the afternoon)
    * Recursion
    * Recursion with helper procedures
    * Numeric recursion
* Reading for Friday
    * [Local Procedure Bindings](../readings/letrec-reading.html)
* Lab Writeup: 
    * Send email titled __CSC 151 Lab Writeup 31 (Your Names)__
    * Do not include the underscores.
    * Send to <CSC151-02-grader@grinnell.edu>
    * Due before class on Monday after break.

### Extra Credit

* Send your reports to <rebelsky@grinnell.edu> with subject 
  "CSC 151 Extra Credit".  (Do not include the quotation marks.)
* Send opportunities to me before class with subject
  "CSC 151 EXTRA CREDIT OPPORTUNITY!"

#### Academic / Artistic

* Cool talk on Cryptography TODAY at 4:15 (Math/CS)

#### Peer

* Film Screening at 4:00 ARH 102, panel afterwards.  Feminism and like
  global stuff.

#### Regular Peer NOT DURING BREAK

* Social Dance Workshop Tuesdays 7:00-8:00 in Bucksbaum Dance Studio.
* Pun club Saturdays at 4pm in Younker.  
* Electronic Potpourri on KDIC Fridays at Five. THIS FRIDAY.
* Space Odyssey KDIC Fridays at Six.  THIS FRIDAY.
* Bollywood, Friday, 7:30-8:30, Younker.  THIS FRIDAY.
* Effective Altruism club, 2:30-3:30 Sundays in JRC 226. NOT THIS SUNDAY

#### Misc

#### Far in the Future

* Lords of the Flies, April.
* ExCo on British Politics Wednesdays at 8:00 in JRC 203.

### Questions

Why Use Helper Recursion?
-------------------------

A lot of the ways we've phrased recursion, the work happens in the future.

   (define sum
     (lambda (lst)
       (if (null? lst)
           0
           (+ (car lst) (sum (cdr lst))))))

   (sum '(3 1 4))
   => (+ (car '(3 1 4)) (sum (cdr '(3 1 4))))
   => (+ 3 (sum (cdr '(3 1 4))))
   etc.

Delayed work, and this phrasing, can be confusing.

The computer also has to build a long list of work to do in the future.

So we look for alternatives.  Something more close to what we do.

Sometimes, it's easier to think about recursion if you think about
using a helper.

(define lav
  (lambda (lst)
    (display (list 'lav lst)) (newline)
    (cond
      [(null? (cdr lst))
       (car lst)]
      [(>= (abs (car lst)) 
           (abs (lav (cdr lst))))
       (car lst)]
      [else
       (lav (cdr lst))])))

How do we fix this?

* Use a helper procedure, like we did earlier.
* Use a local binding, so we only do the computation once.

(define lav2
  (lambda (lst)
    (display (list 'lav lst)) (newline)
    (cond
      [(null? (cdr lst))
       (car lst)]
      [else
       (let ([lav-cdr (lav2 (cdr lst))])
         (if (>= (abs (car lst)) (abs lav-cdr))
           (car lst)
           lav-cdr))])))

Lab
---

