---
title: Eboard 12  Boolean values, predicate procedures, and list filters
number: 12
section: eboards
held: 2018-02-16
link: true
---
CSC 151.01, Class 12:  Boolean values, predicate procedures, and list filters
=============================================================================

_Overview_

* Preliminaries
    * Notes and news
    * Upcoming work
    * Extra credit
    * Friday PSA
    * Questions
* Quiz
* Leftover notes from prior class
* Lab
* Debrief

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

### News / Etc.

* New partners!
* I hope to return exam 1 (and other materials) on Monday.
* I've told a number of people this, so I should say it to the class:
  It's worth the few minutes of your time to look back at each exercise
  on the lab and ask yourself "Why did the designers of the lab ask us
  that question?"  (There isn't always a good answer, but there
  sometimes is.)
* Do you find the eboards useful?
    * Email me if you'd like to volunteer to take them next week.

### Upcoming work

* No lab writeup!
    * When you do lab writeups, please try to get the class number correct.  
       I saw a lot of "Lab 6" for Wednesday's.
    * Please carbon-copy your partner on lab writeups.
* *No reading for Monday!*
* Reading for Wednesday
    * [Naming values with local bindings](../readings/local-bindings)
* [Homework 4](../assignments/assignment04) due next Tuesday
    * I apologize for the incorrect description of the contents.  That
      has been fixed.

### Extra credit (Academic/Artistic)

* Visit the two exhibits at the Faulconer Gallery.

### Extra credit (Peer)

* Midwest Swim and Dive Conference.  10am Friday to 5pm Sunday.
     * 30 minutes counts, as long as there is active swimming or diving
       during the portion you are there.
     * Diving is at 1:30 Friday and Saturday.  The SGA president is a lot 
       of fun to watch.

### Extra credit (Recurring peer)

* Listen to KDIC Wednesdays at 6pm - Witty banter with other personalities
  and/or co-host.  Also Indian, Arabic, and Farsi music.  (Up to two 
  units of extra credit.)
* Peer editing with SS.  Talk to SS about the details.  Make your
  English Lit more literate.

### Extra credit (Misc)

* Participate in Islamic awareness week.
    * Friday at 4pm in CRSSJ: Turkish Delights, Henna
    * Friday at 2:15pm in CRSSJ open prayer
    * Councilwoman event today at 4:15 pm in Drake Community Library.
* Lunar New Year Festival, 6:30 p.m.  Saturday. Harris Gym.

### Other good things

### Friday PSA

* Think in advance what is right for you.
* Everything in moderation.
* Rest.

### Questions

_You said something about a joke related to saving files.  Can you tell
it to us?_

> There is strong evidence that my jokes are not funny, but I'll try.
  (The world may be ending.  At least 20% of the class laughed.)

_How do `#t`, `#f`, and "not false" come together?_

> Good question.  A common component of algorithm is the conditional.
  You ask a question, you make a choice.  Questions/choices are also
  related to repetition: sort and filter.

> Since asking questions is so key to algorithm design, we have a type
  to represent the result questions.  Boolean.  Named after George
  Boole, who developed an algebra of logic of true and false.

> The designers of Scheme decided that they should have a third option.
  Some procedures that normally return a value (string, integer), return
  `#f` to indicate "that was a senseless question".  `assoc` does this.
  `(assoc val lst-of-lsts)` finds the first the first element in 
  `lst-of-lsts` whose car is `val`.  This should work with any data type.
  But what if `val` isn't the car of any element.  In that case,
  `assoc` returns `#f`.

> This decision led to others using `assoc` (and similar procedures) in
  their tests.  But what if `assoc` doesn't return false?  Decision about
  what to do: If `assoc` or whatever procedure we're calling doesn't 
  return false, we'll assume the result is true.

_Why can we only use four "a"s and "d"s in `caddar` and its ilk?_

> I have no idea.  It takes effort to add each of them and at some point
  it seems like the effort to add them outweighs the benefit to having
  them.

> You can also define them.  `(define caddadadadr (o caddar cdadr cadr))`

_Why do I get weird dots when I use `cons`?_

> At this point in the class, you should be using cons with a value and
  a list.  If you don't, Scheme suggests that you are making a mistake
  in an incredibly non-threatening way: It adds a dot in the middle.

_Why do you only remember the name of that student whose name starts with
"T"?_

> Because they are the only one to introduce themselves every time they speak.

Quiz
----

When you are done, revel in the quiet before you are rudely interrupted
by the buzzer.

Leftover topics from prior class
--------------------------------

Observation: Some of you did not have your lab from Monday.  You will
find prior labs useful for all sorts of purposes.  Please ask your
partner to send you the lab at the end of each class.

* We asked you to use that code in part to remind you of those issues.
    * The code you've written might again be useful.
    * You should therefore make sure you have a copy
* We also asked you to use that code to help you practice citing things.

Observation: Many of you found the length and then used that number in
your future calculations.  E.g., `(drop (- 45751 5) lst)`.  You'd be
better off using the call to length.  E.g., `(drop (- (length lst) 5) lst)`.

Observation: Some of you tried to skip exercises 4 and 5 and jump straight
to exercise 6.  But exercise 6 requires exercises 4 and 5.  If you skip
exercises, you should read over them first.

```
;;; Procedure:
;;;   zip->city
;;; Parameters:
;;;   zip, one of those silly zip-code lists
;;; Purpose:
;;;   Exract the city
;;; Produces:
;;;   city, a string
(define zip->city
  (section list-ref <> 3))

;;; Procedure:
;;;   prepend-city
;;; Parameters:
;;;   entry, one of those silly zip lists
;;; Purpose:
;;;   Shove a copy of the city name at the front of the list
;;; Produces:
;;;   citified, a list
;;; Preconditions:
;;;   entry has the form ...
;;; Postconditions:
;;;   (cdr citified) = entry
;;;   (car citified) is a string that names the city
(define prepend-city
  (lambda (entry)
    (cons (zip->city entry) entry)))
```

```
> (cdr (assoc "Grinnell" (map prepend-city zips)))
'("50112" 41.685324 -92.630258 "Grinnell" "IA" "Poweshiek")
```

Lab
---

Don't forget to switch driver/navigator after every question.

No lab writeup!

Debrief
-------

_At last I can use my Java knowledge!_

> Sorry.  Our goal was that we wait until the second half of the semester
  before you could benefit from prior knowledge.

_But I'll get to use loops then, right?_

> Nope.  You get repetition only from things like `map` and, soon, the
  wonderous power of recursion.
