---
title: Eboard 08  Exploring lists
number: 8
section: eboards
held: 2019-02-11
link: true
---
CSC 151 2019S, Class 08:  Exploring lists
=========================================

_Overview_

* Preliminaries
    * Notes and news
    * Upcoming work
    * Extra credit
    * Questions
* Prep
* Lab
* Debrief

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

### News / Etc.

* I updated the `loudhum` library a few times during the weekend.  
  `file->string` is now much faster.  And the procedures you need
  for today's lab are now in the repo.
* I've put together a draft [class code of 
  conduct](../handouts/code-of-conduct).  Please send me any comments
  you may have ("You forgot ..."; "You should word ... better"; "I
  don't think you should include ...")
* I'm returning the quiz.  Once I'm sure that the folks who didn't take
  it on Friday are done, we can discuss the problems.
* When submitting work, please be careful to carbon-copy your partner
  so that they have a record of your work (and so that the grader knows
  who else worked on it).
    * You can also use `to`.
* We often use `lst` as the name of a list.  The first letter is an
  "el", not a one", so we pronounce it "list", not "first".
* Two of you found errors in the regular expression matcher.  Congrats!
  If you're dealing with non-English texts, `\\W` may not always work.

### Upcoming work

* Readings due before class Wednesday
    * [Boolean values and predicate procedures](../readings/boolean)
    * [Conditionals](../readings/conditionals)
* [Assignment 4](../assignments/assignment04) due Tuesday night.
    * Partners assigned via email.
* Exam 1 to be distributed on Wednesday.  It's a take-home exam that
  is due the following Tuesday.
* [Flash cards](../flashcards/flashcards04) due Wednesday at 8:00 p.m.
    * Covers Wednesday/Friday/Monday classes
* _No lab writeup today._
* Quiz Friday
    * Regular expressions
    * List operations

### Extra Credit

#### Extra credit (Academic/Artistic)

* Any Data Week activity this week.
* HackGC weekend of 15-17 February 2019.  (I'm still looking for links.)

#### Extra credit (Peer)

* Conference Swim and Dive meet, 15-17 February 2019.  Dive times to
  be announced later.  (noon or 1, 7pm, Fri and Sat)
* Lunar New Year Celebration, 6pm February 17, Harris Gym

#### Extra credit (Wellness)

* HIIT training, 4:30 pm, Tuesday, Dance Studio, Bear.  (Cap of two EC units.)
* HIIT training, 10:00 am, Saturday, Dance Studio, Bear
* Hatha Yoga, 7:00 pm, Tuesday, Dance Studo, Bear.  (Cap of two EC units.)
* Brazilian Jiu-Itsu, Wednesday and Friday, 6:30, Dance Studio (cap of two
  EC units.)
* Any Sex Week activity this week.  (If you don't feel comfortable telling
  me about the particular activity, you can just say that you participated
  and give a vague reflection.)

#### Extra credit (Misc)

* Host a prospie! (Details forthcoming.)

### Other good things 

### Questions

Is there a way to see a string with newlines in a form that doesn't have the stupid `\n` characters scattered throughout?

> Yes, you can save the string to a file and then open the file.

> Yup.  You can use `(display str)`.  I'll show a demo in DrRacket.

Do we get extra credit for finding errors in the Web site, such as
readings, assignments, and labs?

> You primarily get good will for finding most errors in the Web site.  
  However, everyone gets extra credit when people find errors in the exam.

It feels like we're getting a lot of "vocabulary" (procedure names).  Do
we really need to know all of them by heart?

> You should know in generally what capabilities are possible; on
  quizzes you can guess names.  You should generally be able to translate
  names into behaviors.  I suggest having some form of reference in your
  own words at hand (notes in a book or computer, flashcards, etc.)

Can we go over the quiz?

> Sure.

Do we use three semicolons or four for 6P-style documentation?

> Three.  If you see something else, it's likely that I screwed up.

How do you want the percentage on the homework?

> Whichever form you find easiest.  I would recommend 33/100 or 33 or
  .33 for "33 percent".

On problem one on the homework, can we make any assumptions about the
number of spaces after a sentence?

> There will be at least one (except at the end of the string), but
  there may be more than one.

Do you have a hint for dealing with no spaces at the end of a string?

> `string-append`

Can we use `map` in this assignment?

> Sure.

Can you explain the `"\\1\\1"`?

> In `regexp-replace*`, we sometimes want to refer to parts of the
  pattern (or what matched parts of the pattern).  For example,
  we might decide that text surrounded by curly braces should be
  emphasized (HTML-style).  "Sam {R} says ..." => "Sam <em>R</em> says ..."

> Pattern: "{[^}]*}"

> Replacement: `<em>` + "the bunch of noncurlybraces" + `</em>`

> If we parentehsize the pattern for "bunch of noncurlybraces" in the
  pattern and use "\\1" in the replacement, we achieve that goal.

> `(regexp-replace* #px"{([^}]*)}" str "<em>\\1</em>")`

> (regexp-replace* #rx"{([^}]*)}" "Sam {R} ssays ..." "<em>\\1</em>")
"Sam <em>R</em> ssays ..."
> (regexp-replace* #rx"{([^}]*)}" "Sam {R} ssays {arrh!} ..." "<em>\\1</em>")
"Sam <em>R</em> ssays <em>arrh!</em> ..."
> (regexp-replace* #rx"{([^}]*)}" "Sam {R} ssays {arrh!} {..." "<em>\\1</em>")
"Sam <em>R</em> ssays <em>arrh!</em> {..."
; #px requires two backslashes before braces
> (regexp-replace* #px"\\{([^\\}]*)\\}" "Sam {R} ssays {arrh!} {..." "<em>\\1</em>")
"Sam <em>R</em> ssays <em>arrh!</em> {..."

What about "\\2"?  

> If we have *two* parenthesized expressions on the left, "\\2" refers
  to the second one.

> `(regexp-replace* #px"([a-z]+) or ([a-z]+)" str "\\1\\1\\2")

How do you type `|`?

> On our keyboards, it's right below the backspace.  Shift-backslash.

What's the difference between "\n" and "\\{"?  Why one backslash in
the first case and two in the second?

> A single backslash, as in "\n", is a signal to the Racket string parser
  that you're writing a special character.  In this case, newline.

> A double backslash, as in "\\", is a signal to the Racket string parser
  that you want a backslash.

> The Regular Expression parser wants a backslash and a curly brace to
  represent curly brace.  "\\{" -> String parser treats as "backslash
  curcly brace", sends it to the RegExp parser.

How should we format our code?

> Use Ctrl-i to reindent for clarity.

> When possible, all the parameters to a procedure should be on the
  same line or on separate lines.

How do I stop Outlook from from messing that up?

> Um ... maybe we'll allow you to attach files.

Quiz 2
------

Problem 1: `(define rtr (o reverse (section take <> 3) reverse))`

* `o` composes functions, building a new function that applies
  each of them from right to left
* E.g., `(o f g h)`, apply `h`, then `g`, then `f`.
* In `rtr`, what gets applied first?  `reverse`, then the weird
  `section` thing, then reverse again.
* What is `(section take <> 3)`?  It's a procedure that takes
  the first three items in the list.  Think of it as
  `(lambda (x) (take x 3))`.
* `(rtr '(a b c d e))`, reverse, take 3, reverse.
     * reverse: '(e d c b a)
     * take 3: '(e d c)
     * reverse '(c d e)
* `(rtr (range 6))`, evaluate range, reverse, take 3, reverse
     * `(range 6)` - `'(0 1 2 3 4 5)`
     * reverse: `'(5 4 3 2 1 0)`
     * take 3: `'(5 4 3)`
     * reverse: `'(3 4 5)`
* `rtr` grabs the last three elements of a list, provided the list has
  at least three elements.


Problem 2: Computing x^4.

Using `lambda`

```
(define quad
  (lambda (x)
    (expt x 4)))
```

Using `section`

```
(define quad (section expt <> 4))
```

Using `o`

```
(define quad (o sqr sqr)) 
```

Prep
----

Big picture: _When you combine values in lists, you can do lots of
interesting things._  We're considering just a few of them.

* `sort` - put them in order (numerical, alphabetical, other)
* `tally-value` - count
* `map` - do something to each one
* `reduce` - repeatedly do something to neighboring pairs
     * `reduce-left` - moving left to right
     * `reduce-right` - moving right to left
     * `reduce` - somewhat random

Lab
---

Why did you have `iota` rather than `range`?

> A list-minute change to the `loudhum` library.  We've used `iota`
  in past semesters and decided on `range` this semester.

Why "Large Illness"?

> In tribute to Kumail's "The Big Sick"


