This class will be recorded! Its use is limited to members of the class. Please do not share with others.
Approximate overview
Attend (or watch recording within a day or so) and send a one-paragraph reflection asap afterwards.
Only those activities I list count.
Mini Projects
Readings
Quizzes
Other
Will you answer a question about the sample problems?
Yes, in class tomorrow.
The mentors will answer some tonight.
I’ll also answer some on Teams.
Will we have to trace through vector code or write procedures?
Yes. Sam added the trace questions because tracing helps you better understand what’s going on, which better prepares you.
match? is 23 lines of code (plus some comments)match is 34 lines of code
(plus some comments), with no helpers.match is 38 lines of
code, including the code in helpers (but not including comments).find-match is 7 lines of code, using if, and, and
or, with no helpers (other than match?)match is 17 lines
of code, none of which has more than four “words” on it,
plus some parentheses and brackets. (Yes, that’s short enough.)Nope
Select a random number between 80 and 100, inclusive.
People who know random better than Sam wrote:
(define random-grade
(lambda ()
(random 80 101)))
That is, random can take two parameters and generate a random integer
between the lower bound (inclusive) and the upper bound (exclusive).
Sam didn’t know that there’s a random with two parameters, so he
expected something like the following. There are twenty-one different
numbers that the procedure might generate.
(define random-grade
(lambda ()
(+ 80 (random 21))))
More negative people wrote:
(define random-grade
(lambda ()
(- 100 (random 21))))
My procedure counts syllables. But it takes lists of characters instead of strings. How do I do that with Jayne Eyre?
You should be splitting Jayne Eyre into a list of words.
And you can then filter that list appropriately.
(define three-syllable words (filter (o (= <> 3) count-syllables) je))
Should we use file->lines or file->words?
I was assuming
file->stringand then some clever additional work, likestring-replaceorremove*and thenstring-split.
(string-replace
(string-replace (file->string "jayne-eyre.txt") "\r" "")
"\n
"")
For “Write a procedure (abab words) that takes as input a corpus
(list) of words and generates a “random” quatrain of four lines of
four words. The last words of the first and third lines must rhyme,
as must the last words of the second and fourth lines.” do we use
one corpus or two?
I’d prefer one, which is how I specified it.
If your aesthetics suggest two words, you can write another procedure,
(abab2 awords bwords), and then rewriteababas a call to that.
(define ababa
(lambda (words)
(abab2 words words)))
Does it still count as a rhyme if it’s the same word?
Yes. This is experimental code. And what if your word is orange?
How do you show a downward arrow in ASCII art?
If the first section has a downward arrow, it’s the first parameter to the
cons.
cons.Why use a list over a vector?
Lists are dynamic: You can extend them with
consand shrink them withcdr. That’s often easier/faster than building a new vector.
To change the size of a vector, you need to build a new vector and copy everything over.
Lists are immutable, which leads to some clarity.
Can you talk about why immutability adds to clarity?
> (define vec1 (vector 'a 'b 'c 'd))
> (define lst1 (list 'a 'b 'c 'd))
> (define vec2 vec1)
> (define lst2 lst1)
> ; How do we make `e` the first symbol of `lst1`, replacing 'a.
(cons 'e (cdr lst1))
'(e b c d)
> (define lst1 (cons 'e (cdr lst1)))
> lst1
'(e b c d)
> ; Will that change lst2?
; Is lst2 the same?
; Because lst2 was lst1 but ...
lst2
'(a b c d)
> vec1
'#(a b c d)
> ; How do I set the first element of vec1 to 'e?
(vector-set! vec1 0 'e)
> vec1
'#(e b c d)
> ; Have we changed vec2? Yes.
> vec2
'#(e b c d)
When you change something in a vector, you may find that something you didn’t expect to change changes.
What happened?
Because lists are immutable, when we rebuilt
lst1, we actually built a new list (a new cons at the start, etc.) Solst1became something different.
However,
vec1andvec2refer to the same vector. If we change one (vectors are mutable), we change the other.
How can we define a copy of a vector?
With the confusingly named
vector-copy.
> (define vec1 (vector 'a 'b 'c 'd))
> (define vec2 (vector-copy vec1))
> (vector-set! vec1 0 'E)
> vec1
'#(E b c d)
> vec2
'#(a b c d)
Is it dangerous to define a vector as the result of applying a procedure to another vector?
It can be. But some procedures return new vectors, and that’s okay.
There’s a reason we don’t have the ! procedures return vectors.
Will you go over the self-check problems?
Nope. Discuss them with your partners and then call in a staff member.
For the table model, I couldn’t figure out how to make the set-phone!
work.
See the prior question.
Where should citations go?
I like general citations at the top and specific citations in the body.
I care more about the attempt than the perfection of the attempt.
Is there a line between the two?
Do both!