Approximate overview
Events
Other good things
When will we get assignments back?
Yes.
How do you make text labels in DrRacket?
Look it up.
See Sam’s examples.
(text "STRING" SIZE 'COLOR)
Process: Sam gathers questions. Sam answers questions. Students ask followup questions along the way. Repeat.
Should we redo things we got correct last time?
No
Is there still a time limit?
Yes. You should be able to do each in about ten minutes, but you have an hour. (If you have accommodations, you have your accommodation factor times one hour.)
Will the redos be similar or updated with new stuff we’ve learned?
Potentially updated with new stuff you’ve learned. For example, the tracing problem is almost certainly for a recursive procedure and uses conditionals.
Wheeeeee
I agree.
What do you care about for program style?
Good variable names.
Good line breaking. Don’t put everything on one line. Follow conventions.
https://rebelsky.cs.grinnell.edu/Courses/CSC151/2021Fa/handouts/style-guide
Also Embrace the Zen of Booleans.
https://rebelsky.cs.grinnell.edu/Courses/CSC151/2021Fa/handouts/zen-of-booleans
How many characters should a line be?
I prefer no more than 80.
Try to limit yourself to no more than eight “words” on a line.
Do you want us to do the long, drawn out tracing?
Yes.
For the Rex question, do we have to write a Rex?
You may have to write a Rex. You may have to read Rexes. You may have to do both. (Probably write.)
Can we do an example of recursive tracing? (Or any tracing.)
;;; (largest-integer nums) -> integer?
;;; nums : listof integer?
;;; Finds the largest integer in the list.
(define largest-integer
(lambda (nums)
(if (null? (cdr nums))
(car nums)
(max (car nums) (largest-integer (cdr nums))))))
Three or so rules for tracing.
if, and, and other stuff like
that, evaluate all the parameters to a procedure before applying the
procedure.(if TEST CONSEQUENT ALTERNATE), first evaluate the
test, which will be truish or false. If the test is true (#t) or
truish, replace the if with the CONSEQUENT. If the test is false
(#f), replace the the if with the ALTERNATE. After replacing, continue. (largest-integer '(5 1 6 4))
--> (if (null? (cdr '(5 1 6 4)) (car '(5 1 6 4)) (max (car '(5 1 6 4)) (largest-integer (cdr '(5 1 6 4)))))
-->
--> (if (null? '(1 6 4)) (car '(5 1 6 4)) (max (car '(5 1 6 4)) (largest-integer (cdr '(5 1 6 4)))))
--> (if #f (car '(5 1 6 4)) (max (car '(5 1 6 4)) (largest-integer (cdr '(5 1 6 4)))))
--> (max (car '(5 1 6 4)) (largest-integer (cdr '(5 1 6 4))))
--> (max 5 (largest-integer '(1 6 4)))
--> (max 5 (if (null? (cdr '(1 6 4))) (car '(1 6 4)) (max (car '(1 6 4)) (largest-integer (cdr '(1 6 4))))))
--> (max 5 (if (null? '(6 4)) (car '(1 6 4)) (max (car '(1 6 4)) (largest-integer (cdr '(1 6 4))))))
--> (max 5 (if #f (car '(1 6 4)) (max (car '(1 6 4)) (largest-integer (cdr '(1 6 4))))))
--> (max 5 (max (car '(1 6 4)) (largest-integer (cdr '(1 6 4)))))
--> (max 5 (max 1 (largest-integer '(6 4))))
--> (max 5 (max 1 (if (null? (cdr '(6 4))) (car '(6 4)) (max (car '(6 4)) (largest-integer (cdr '(6 4)))
--> (max 5 (max 1 (if (null? (4)) (car '(6 4)) (max (car '(6 4)) (largest-integer (cdr '(6 4)))))))
--> (max 5 (max 1 (if #f (car '(6 4)) (max (car '(6 4)) (largest-integer (cdr '(6 4)))))))
--> (max 5 (max 1 (max (car '(6 4)) (largest-integer (cdr '(6 4))))))
--> (max 5 (max 1 (max 6 (largest-integer (cdr '(6 4))))))
--> (max 5 (max 1 (max 6 (largest-integer '(4)))))
--> (max 5 (max 1 (max 6 (if (null? (cdr '(4))) (car '(4)) (max (car '(4)) (largest-integer (cdr '(4))))))))
--> (max 5 (max 1 (max 6 (if (null? '()) (car '(4)) (max (car '(4)) (largest-integer (cdr '(4))))))))
--> (max 5 (max 1 (max 6 (if #t (car '(4)) (max (car '(4)) (largest-integer (cdr '(4))))))))
--> (max 5 (max 1 (max 6 (car '(4)))))
--> (max 5 (max 1 (max 6 4)))
--> (max 5 (max 1 6))
--> (max 5 6)
--> 6
And we’re supposed to do that in ten minutes?
Maybe you’ll get a slightly smaller problem.
Can we write the documentation for matching-indices?
a.
;;; (matching-indices pred? lst) -> listof integer?
;;; pred? : predicate? (procedure that returns #t or #f)
;;; lst : list?
;;; Finds the indices of elements of a list that match a particular predicate.
b.
The predicate must be sensibly applicable to all elements of lst.
c.
We can guarantee that (pred? (list-ref lst i)) is truisih.
Can we do a sample “write a Rex” problem?
Write a regular expression for words that start and end with a lowercase vowel and have only lowercase consonants inside, with at least one consonant. E.g., alpha, eye, aye. uh: Use help.
(define rex-vowel (rex-char-set "aeiou"))
(define rex-consonant (rex-char-set "bcdfghjklmnpqrstvwxyz"))
(define rex-consonants (rex-repeat rex-consonant))
(define this-rex (rex-concat rex-vowel rex-consonants rex-vowel))
Sam notes that he will not expect your regular expressions to work in the
way he thought they should with rex-find-matches.