CSC151.01 2014F, Class 23: Revisiting Lists
===========================================

_Overview_

* Preliminaries.
    * Admin.
    * Upcoming Work.
    * Extra Credit.
    * Questions.
* Lists, revisited.
* Lab.

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

### Admin

* New partners!
* Office hours 
    * Normal (MThF 1:45-3:15; walking 1:15-1:45) 
    * In the Grill 8:00-9:30 Wed and Fri
    * In my office 8:00-9:30 Thu
* Review sessions Wednesday and Thursday at 8pm (led by Evan)

### Upcoming Work

* Writeup (due Fri): Problem 4, <http://bit.ly/151-2014F-w23>
* [HW 5](../assignments/assignment.05.html) due tonight.
* Exam 2 will be distributed tomorrow.
* Reading for Wednesday:
    * [Recursion Basics](../readings/recursion-basics-reading.html)
    * We will spend at least two days on this topic, so don't worry if
      it seems hard.

### Cool Things Coming to Campus

* Two versions of _Anna Christie_!
* Live Streaming of Verdi's _Macbeth_, Saturday at 11:55 a.m.
* Pop-up Exhibit, Thursday October 9th, all day in BCA 132

### Extra Credit Opportunities

#### Academic

* Grinnell Prize events this week (particularly events related
  to the prize winners whose project involves Web tools)
* Artist Talk, Wednesday October 8th at 4:15pm in BCA 152
  Rewriting the Application Programming Interface (API) for Art Making
* BCC Faculty Chat, Tuesday, October 14, 7pm

#### Peer Support

* Football (Saturday at 1pm)
* Swimming October 18: Alumni Weekend
* 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
* The College's version of _Anna Christie_, Oct. 9-12 (SB plays Marthy)
* Men's Tennis (???)
* Women's Tennis (???)

### Questions

* Note that I tend to respond more quickly to email questions than questions
  posted to the form.

_Could you explain Problem 2 on Assignment 5?_

_Please explain Euclidean distance_

> Requires whiteboard.  (Sam will try to transcribe.)

Lists, revisited
----------------

* Original model: Homogeneous collections
    * Make them with `list`, `make-list`, `iota`
    * Build new lists from old with `map`
    * Join lists with `append`
    * `reverse` - obvious
    * `list-take` and `list-drop` - build a new list by taking the first
      N elements or dropping the first N elements
* New model: Lists are collections that may be heterogenous and that
  you might decompose
    * `car` - get the first element
    * `cdr` - get all but the first element
    * `cadr` - get the second element
    * `cons` - given a value and a list, build a new list by shoving a
      value on the front
    * `list-ref` - given a list and a number, extract the particular
      value from the list
* We can now work with individual elements, rather than doing the
  same thing to every value

_Is there a way to put an element at the end of a list?_

> No built-in one, but you can probably figure out some strategy.

        (append lst (list val))

        (reverse (cons val (reverse lst)))

_How do you get the last element in a list?_

        (list-ref lst (+ -1 (length lst)))

        (car (reverse lst))

Lab
---

_How do we refer to the empty list?_

> Any of the following

        null
        '()
        (list)
        (make-list 0 "anything")

> I prefer `null`.

_Why do the indices start with 0 rather than 1?_

> Computer scientists like to start counting with 0.

> It lets you think of `(list-ref lst i)` as "take the `cdr` i times, then
  take the `car`"

_What would lead you to name three lists `one-two`, `won-too`, and `want-to`?_

> Lack of sleep.

> Congratulations, you are the last class that will ever have to deal
  with these stupid names.

_Why did we have that exercise?_

> To reinforce that "if you ssee a period, it's not a list"

_What do you think of the following code to find element 5 using `cdr` and `car`?_

        ((o car cdr cdr cdr cdr cdr) letters)

> Creative.

_What do you think of the following for `rectangularize`?_

        (define rectangularize 
          (lambda (drawing)
            (list 'drawing 'rectangle
                  (list-ref drawing 2)
                  (list-ref drawing 3)
                  (list-ref drawing 4)
                  (list-ref drawing 5)
                  (list-ref drawing 6)
                  (list-ref drawing 7))))

> My, that's a lot of work.

