CSC151.02 2016S, Class 38: Vectors
==================================

_Overview_

* Preliminaries.
    * Admin.
    * Upcoming Work.
    * Extra Credit.
    * Questions.
* A bit more on pair structures.
* Vectors lab.

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

### Admin

* Same partners!
* I will continue to bring you food (or food-like substances) until I am 
  caught up on grading.
* I have not had the opportunity to read much email today.  I'm also
  watching my son play soccer in Pella.  If you sent a question, I probably
  won't get to until 9:00 p.m.

### 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.
* Review Sessions
    * Wednesday at 8pm in CS commons with Sarah (?)
    * Thursday at 8pm in CS commons with Kumar.
    * None with Sam this week

### Upcoming Work:

* *No reading for tomorrow.*
* Lab Writeup:
    * Send email titled __CSC 151 Lab Writeup 38 (Your Names)__
    * Do not include the underscores.
    * Send to <CSC151-02-grader@grinnell.edu>
    * Due before class on Monday.

### 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

* Talk Wednesday, 4pm, ARH 302
* Talk Thursday, 4:15 pm, ARH 102, 
  The Stability of Value-added Measures of Teacher Effectiveness Derived 
  under Different Growth Models
* Student Research Symposium this week
* Symphony Orchestra with Dave Stamey, Herrick. April 16, 7:30-9:00 p.m.
* Any of the fora on the report from the Residential Learning Task Force.
  (Formal announcement forthcoming.)
     * April 15: Open task force meeting, 1:00-2:30pm in JRC 209
     * April 18: Listening session, 8:00-9:00pm TBD
     * April 22: Open task force meeting, 1:00-2:30pm in JRC 209
     * April 26: Listening session, 6:00-7:00pm TBD

#### Peer

* Lords of the Flies, 7:30 pm April 22nd, 2:00 pm April 23rd, 2:00 9pm April 24th.  (Only 50-60 tickets per show)
* ISO, Saturday, April 16, 7-9 p.m.  Various classmates performing at
  various times.
* Second Annual Contra into Spring Dance, April 22nd, Main Quad, 7:30 p.m.

#### Miscellaneous

* Host a prospective student this coming weekend.

#### Regular Peer 

* Social Dance Workshop Tuesdays 7:00-8:00 in Bucksbaum Dance Studio
* Post-break ExCo on British Politics Wednesdays at 8:00 in JRC 203.  
  Just show up; you don't need to sign up.
* Pun club Saturdays at 4pm in Younker 
* Electronic Potpourri on KDIC Fridays at Five 
* Space Odyssey KDIC Fridays at Six
* Bollywood, Fridays, 7:30-8:30, Younker
* Effective Altruism club, 2:30-3:30 Sundays in JRC 226.

#### Misc

#### Far in the Future

* Adaptation of Rushdie's East West.  Early May.

### Questions

_What was yesterday's writeup?_

> Exercise 3.

_What should `rac` and `rcd` return when given `null` as input?_

> What do `car` and `cdr` return when given `null` as input?

_What's wrong with my stencil procedure?_

> Most common answer: You don't have to fit everything into one `let` or
  `letrec`.  You can nest forms of `let`.

> Second most common answer: You need to recompute the random column and
  row at each repetition.  Think about your ordering of operations.

> Third most common answer: Since there's call to `image-new` at the
  top of `stencil-quarter-circle`, don't recursively call
  `stencil-quarter-circle`.  Use `repeat` or use a helper.  (Sam
  prefers local helpers, but will cope with non-local helpers in many
  cases.)

_Can you demo `image-set-pixel!`?_

> Sure.  Done.

_Can you explain the formula for problem 6?_

> The area of a circle is pi*r*r.  If the radius is 1, the area of a 
  circle is pi.  If it's a quarter circle, the area is pi/4.  We're 
  approximating the area of the quarter circle.  We can then run the
  formula backwards to get pi.

> See the board for more details.

_But how do I get a random number between 0 and 1?_

> `(random)`.

_I've written `irgb-closest` using that "doubly recursive method" which
 we've seen is horribly inefficient.  Will you penalize us for that?_

> Yes.  Lots!  (If I'm in a good mood when grading, and you have nothing
  else wrong with your solution, you'll be lucky to get a 6/10 on that
  problem.)

_Do you expect us to think at least a little bit about efficiency?_

> Yes.

_What about empty substrings?_

> Look at the postconditions.

<pre class="programlisting">
> (define str "Hello World")
> (define substr "")
> (define pos 0)
> (equal? (substring str pos (+ pos (string-length substr))) substr)
#t
> (define pos 5)
> (equal? (substring str pos (+ pos (string-length substr))) substr)
#t
> (define pos 1253)
> (equal? (substring str pos (+ pos (string-length substr))) substr)
. . substring: starting index is out of range
  starting index: 1253
  valid range: [0, 11]
  string: "Hello World"
</pre>

_How much extra credit should we get for identifying the massive typo
 on how to submit?_

> At least two units.  Email it to me, like always.

_What is my number?_

> The same one as last time.

_I lost it._

> (random 1000000) ; add any leading 0's

_Do you really want dead trees?_

> No.  Point.

_Are we ever getting to the main class material?_

> Maybe.  Conveniently, tomorrow is a "pause for breath" and you can
  do the lab then.

_Are you really taking off one point for each minute a student was
 late to today's class?_

> Considering it.  (And yes, that's 50 points for people who missed class,
  and 30 minutes for ....)

A Bit More on Pair Structures
-----------------------------

Why are we doing this?  (That is, looking at pair structures and vectors.)

Why are we studying pair structures, given that we know about list?

* To give us a better understanding of `car` and `cdr`.  `car` is the
  thing that the first box points to (aka the contents of the first
  box), `cdr` is the thing that the second box points to.
* Gives you a deeper understanding of how Scheme works.
    * Scheme does a lot of "reference chasing" (following arrows)
    * List processing is generally slow, so look for ways to avoid it.
* We use linked structures a *lot* in CS; knowing more about linked
  structures turns out to be useful.
* Soon, we will build more complicated linked structures using pairs
  (or something similar).  Pictures help you understand.
* Understand the stupid dot at the end of each non-list.

Why are we studying vectors?

* Vectors provide an interesting alternative to lists because they seem
  more efficient.
* For example, vectors let you change them without creating a new vector.
* Vectors let us quickly find any element because we can compute its
  location.
* In contrast, finding an element in a vector can be slow.
* Vectors are hard to resize, though.
* Is there a `car` for vectors?  Not really.  There's `vector-ref`
* Is there a `cdr` for vectors?  No.  

Vectors Lab
-----------
