---
title: Eboard 16  Preconditions, revisited
number: 16
section: eboards
held: 2017-09-29
---
CSC 151.01, Class 16:  Preconditions, revisited
===============================================

_Overview_

* Preliminaries
    * Notes and news
    * Upcoming work
    * Extra credit
    * Friday PSA
    * Questions
* An example from Wednesday
* Quiz
* Lab

### News / Etc.

* New partners.  
* Please make sure to return your computer cards to the jar.
* I was sorry to see so few of you at the Wilson Okello convo.  It was
  one of the better convocations I've seen.

### Upcoming Work

* [Writeup for class 15](../writeups/writeup15) due TONIGHT at 10:30 p.m.
    * Exercises 5 and 6
    * To: <csc151-01-grader@grinnell.edu>
    * Subject: CSC 151.01 Writeup 15 (YOUR NAMES)
* No writeup for today's class.
* [Assignment 5](../assignments/assignment05) due Tuesday at 10:30 p.m.
* Reading for Mondays's class: [Recursion basics](../readings/recursion-basics)

### Extra credit (Academic/Artistic)

* Any of the many Grinnell Prize events.
* CS Table, Tuesday: Tapia.

### Extra credit (Peer)

* Women's Tennis vs. Cornell, Noon, Sunday (high-school courts)
* Volleyball vs. Knox Tuesday at 7:00 p.m.
* Volleyball vs. Beloit, next Friday at 7:00 p.m.
* Men's Soccer Wednesday at 4:30 vs. Cornell

### Friday PSA

* Think about your choices, in advance.
* Self gov (individually and collectively)
* Consent is absolutely positively necessary.  But you should strive
  for more than consent.

### Questions

What is the difference between a Boolean and a predicate?
  : Booleans are basic values, like integers, reals, and strings.  The two Boolean values are `#t` and `#f`.  The design of Scheme is such that anything that's not a Boolean is treated as "truish" and equivalent to `#t` in conditioanls.
  : Predicates are procedures that return Boolean values.
  : We put question marks after both predicates and Boolean values to highlight that they are or return true/false.

Can you help with problem 1 on the homework?
  : Sure.  Let's look at what [the problem](../assignments/assignment05) says.
  : Step one: Read all the words from the file, `file-words`
  : Step two: Convert to a list of lengths.  `map`
  : Step three: Tally. `tally-all`
  : Step four: Scale.  `map`
  : Step fourb: What do we map with?  Something that divides the second
    element by the number of words.
  : Step five: Sort

```
(define explore-lengths
  (lambda (fname)
    (let* ([words (file->words fname)]
           [num-words (length words)]
           [scale-second (lambda (pair) 
                           (list ... (/ (cadr pair) num-words)))]); Divide the second element by num-words
      (plot 
       (discrete-histogram
        (sort (map ... 
                   (tally-all (map FUNCTION 
                                   words)))
              (comparator ...)))))))
  ```

I'm not sure what to put as the postconditions for `explore-lengths`.
  : Yeah, that's a hard one.  You can't be as precise, but say something
    about the number of bars you see and such.

For problem 1 (and others), how do I submit the graphs?
  : Don't.

For problem 1, what should I do about word lengths that aren't included?  I feel like it distorts the results.
  : Ideally, you'd come up with a clever solution.  But it's a rare
    enough case that I do not require you to come up with a solution.

What's the goal in problem 3?
  : To make a collection of "nearby" words, where "nearby" means
    appearing immediately after, or two after, or three after a
    word

Shouldn't I get a length that is a multiple of 3?
  : Usually yes.  But there are some cases in which the word appears
    at the end, so you don't get a multiple of three.

An example from Wednesday's class
---------------------------------

```
(define zips (read-csv-file "/home/rebelsky/Desktop/us-zip-codes.csv"))
(define zips3 (filter (lambda (entry)
                        (string-equal? (substring (car entry) 0 3) "021")))
              zips)


(define lat-lon
  (lambda (entry)
    (list (cadr entry)
          (caddr entry))))

(define lon-lat
  (lambda (entry)
    (list (caddr entry) (cadr entry))))

;(plot (points (map lat-lon (filter useful-entry? zips))))

;(plot (points (map lon-lat (filter useful-entry? zips))))

;(plot (points (map lon-lat (filter useful-entry? zips))
;              #:x-min -150
;              #:x-max -50))
;(plot (list
;       (points (map lon-lat (filter useful-entry? zips))
;               #:x-min -150
;               #:x-max 0)
;       (points (map lon-lat (filter useful-entry? zips3))
;               #:sym 'fullcircle6
;               #:fill-color "red")))
```

Quiz
----

Double-sided.  Whoo!

Lab
---

Insufficient time.  Whoo!  

Yes, problem 2 is a big `and` statement

```
(define city?
  (lambda (thing)
    (and (list? thing)
         (= (length thing) 6)
         (string? (list-ref thing 0))
         (real? (list-ref thing 1))
         ...)))
```

No writeup!  Please do take the time to read through all of the problems,
though, and to attempt them.

Debrief
-------
