EBoard 21: Pause to Review

Approximate overview

  • Admin
  • Q&A for SoLA
  • Surprise!

Administrative stuff

Introductory notes

  • Please disinfect your keyboard and mouse; there are many colds and such going around campus.
  • Happy Rainy Day.
  • During break, I’m going to open up the deadlines for readings and labs so that those who didn’t get them in can catch up.
  • A particularly serious comment. If I see you pulling a keyboard out of your partner’s hand, or otherwise damaging your partner’s learning, I will remove you from this class.

Upcoming activities

Events

  • CS Extras Thursday at 4pm: Explainable Planning and Decision Making + Overview of CSE and DCDS Programs at WashU
  • Saturday: Scarlet and Black meet

Other good things

  • 4:30 pm Wednesday, Men’s Soccer (maybe)
  • 7pm Wednesday Volleyball
  • 11:00 am Thursday, Math Talk on Summer Research

Upcoming work

Analyses

  • Fun fun fun
  • Make sure to have two images (preferably with book names)

Non-SoLA Q&A

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)

SoLA Q&A

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.

  • ORDER OF EVALUATION rule: Except for if, and, and other stuff like that, evaluate all the parameters to a procedure before applying the procedure.
  • PROC rule: If you have a function call to a user-defined function, you replace it with the body of the function, substituting parameters appropriately.
  • IF rule: To evaluate (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.