Overview
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.to
.lst
as the name of a list. The first letter is an
“el”, not a one”, so we pronounce it “list”, not “first”.\\W
may not always work.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 R 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 …” “\1”) “Sam R ssays …” (regexp-replace #rx”{([^}])}” “Sam {R} ssays {arrh!} …” “\1”) “Sam R ssays arrh! …” (regexp-replace #rx”{([^}])}” “Sam {R} ssays {arrh!} {…” “\1”) “Sam R ssays arrh! {…” ; #px requires two backslashes before braces (regexp-replace #px”\{([^\}]*)\}” “Sam {R} ssays {arrh!} {…” “\1”) “Sam R ssays arrh! {…”
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.
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(o f g h)
, apply h
, then g
, then f
.rtr
, what gets applied first? reverse
, then the weird
section
thing, then reverse again.(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.
(rtr (range 6))
, evaluate range, reverse, take 3, reverse
(range 6)
- '(0 1 2 3 4 5)
'(5 4 3 2 1 0)
'(5 4 3)
'(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))
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
- countmap
- do something to each onereduce
- repeatedly do something to neighboring pairs
reduce-left
- moving left to rightreduce-right
- moving right to leftreduce
- somewhat randomWhy did you have iota
rather than range
?
A list-minute change to the
loudhum
library. We’ve usediota
in past semesters and decided onrange
this semester.
Why “Large Illness”?
In tribute to Kumail’s “The Big Sick”