EBoard 17: See yesterday’s class

This class will be recorded! Its use is limited to members of the class. Please do not share with others.

Approximate overview

  • Administrative stuff [~10 min]
  • Q&A [~10 min]
  • MP4 [~5 min]
  • No Quiz [~0 min]
  • Return to tally-value [~20 min]
  • Lab [~45 min]

Administrative stuff

Notes and News

  • Happy Tuesday.
  • Sorry for yesterday’s class; hitting my head on the board clearly had an effect on my ability to teach.
  • You should know the drill on evening tutoring. Please use the evening tutors. Please consider visiting them in person (if you are on campus).
  • Note: The new lab policy is that you can turn in what you’ve done when you reach 4:30 p.m. (I’d recommend that you do the rest at some point, to make sure you understand, but I want to respect your time.)
  • I am sorry to report that some members of your class seem to be having trouble treating each other well in pair work.
    • Please try to do better.
    • Please reach out to me if you encounter issues.
    • Remember: “How do be a decent human being” is supposed to be a learning outcome of this course.

Upcoming activities and other token-earning things

Events

  • Mentor session Wednesday at 7 pm. Practice for SoLA 2!
    • Write it up to get a token.
  • CS major declaration information session Thursday at 5pm.
    • This will be recorded.
  • 4+1 BA/MS in CS Program w/UIowa info session Friday at noon.
  • Restorative Justice Circles info session Friday at noon
    • Or any of the circles themselves.
  • CS Table Monday, 1 March 2021 at noon. Chapter 1 of the book.
  • WGMC presents Ethics and Social Justice in CS. 6pm, Wednesday, 3 March 2021.
  • Journalism Ethics Workshop, 7:00-8:30 pm, Thursday, March 4 and Tuesday, March 9
  • Support a local bakery (such as GrinCity)

Upcoming work

I’m not sure if all of these links are correct. Let me know if any are not.

Q&A

Why did my tokens disappear?

Gradescope is evil. Perhaps more evil than Sam.

Mini-Project 4

What’s our goal?

Take numbers (or other info) you come up with and use them as characteristics of the images you generate.

Exploring Tally

This text is retained from yesterday’s class.

We’re using tally or tally-value a lot on this procedure. Let’s explore how it might work, or at least how we might trace it conceptually. We’ll assume that it has to work step-by-step, looking at each value in turn.

    (tally-value '(b a c a b a) 'a)
    ; The b is not the same as a, so it won't contribute to our overall
    ; tally.  Throw away.
    ; We should go on to the next thing
--> (tally-value '(a c a b a) 'a)
    ; Compare the a to a.  They are the same.
    ; Add 1 to the count
    ; And then move on to the rest of the list
--> (+ 1 (tally-value '(c a b a) 'a))
    ; Compare c to a.  No.  Continue on
--> (+ 1 (tally-value '(a b a) 'a))
    ; Compare a to a.  Same.  Add 1 and continue
--> (+ 1 (+ 1 (tally-value '(b a) 'a)))
    ; Compare b to a.  Different.  Throw away the b and continue
--> (+ 1 (+ 1 (tally-value '(a) 'a)))
    ; Compare a to a.  Same.  Add 1 and continue
--> (+ 1 (+ 1 (+ 1 (tally-value '() 'a))))
    ; There are 0 a's in the empty list.  We're done.
--> (+ 1 (+ 1 (+ 1 0)))
--> (+ 1 (+ 1 1))
--> (+ 1 2)
--> 3

Questions

If we were using strings and wanted to be case insensitive, would it be different?

Our trace would be similar.

E.g., (tally? (section string-ci=? <> "Eh") list-of-words) would require that we ask “Is the first word equivalent to “Eh”, ignoring case?” rather than “Is the first element ‘a?”

Our code would be somewhat diffeent.

Can we do more practice tracing at some point?

A great thing to do with the evening tutors.

Writing tally-value

Goal: Get Schemy with what we were trying to do. That is, suppose that we have to write tally-value on our own, where would we start?

Sam: We should start with documentation!

Things that would be useful within tv:

  • Since we’re dealing with lists, car will be useful to get the first value.
;;; (tv lst item) -> integer?
;;;   lst : list?
;;;   item : any?
;;; Compute the number of times the item appears in the list.
(define tv
  (lambda (lst item)
    (cond
      ; Option 1: Empty list
      [(null? lst)
       0]
      ; Option 2: Front matches
      [(equal? item (car lst))
       (+ 1 (tv (cdr lst) item))]
      ; Option 3: Front doesn't match
      [else
       (tv (cdr lst) item)])))

(test-equal? "Element occurs once, at front" (tv '(1 2 3 4 5) 1) 1)
(test-equal? "Edge case: Empty list" (tv '() 'a) 0)
(test-equal? "Edge case: Strange value" 
             (tv (list (circle 5 'solid "black")
                       (circle 5 'solid "red")
                       (circle 5 'solid "black")
                       (circle 5 'outline "red"))
                 (circle 5 'outline "black"))
             0) 
(test-equal? "Value appears multiple times"
             (tv (list 'a 'b 'a 'a 'c 'e) 'a)
             3)

Lab

Have fun. Be good to each other.