EBoard 07: Pause for Breath

Approximate overview

  • Administrative stuff (including attendance) + Q&A [20 min est, 45 min actual]
  • Finish (or make progress on) Wednesday’s lab [40 min est, 45 min actual, insufficient]
  • Other discussions [20 min, 0 min actual]

Administrative stuff

Introductory Notes

  • Don’t forget to sit in the same place as the second half of last class.
  • Happy Friday.
  • I hope the first Mini-Project went well.
  • When you post questions, it’s nice if you title them so others can quickly skim.
    • Click on the A+Pen icon.
    • Add a subject where it says “Add A Subject”
    • Type where it says “Start a new conversation”.
    • Click the button that looks surprisingly like a paper airplane.
    • I will attempt to demonstrate.
  • “I didn’t want to get less than an E, so I pushed way too hard.”
    • Amazingly, you have the opportunity to redo assignments. And all you have to do is fix the things that stopped you from getting an E (or an M, if that’s your goal).
  • Don’t worry that some of your partners did overkill on this first HW; many of them come with prior experience and it won’t affect your grade.
    • I don’t think they meant to intimidate you.
    • When I think of the best students I’ve had in the past twenty-five years, most did not have prior experience.
  • Yes, I will show you all the (basic) pictures on Monday.

Friday PSA

  • If you imbibe alcoholic beverages, please stay in moderation. There are data on how much alcohol will affect you depending on gender and body weight (apologies that the data assumes a binary).
    • Fake solo cups do not have the “1 shot” line in the correct place.
  • Remember that other drugs are illegal (some appropriately, some inappropriately), please know the likely effects of the drugs you consume (if you consume drugs), and please do so in moderation.
  • If you cohabit, please obtain consent. Consent is necessary. Absolutely necessary.
  • Masks! We’re in a time of covid.
  • Be an active bystander!

Upcoming activities

Events

  • CS Department 1st/2nd-year Meet and Greet in the CS Commons at 4pm today.
  • Mentor session Sunday at 4pm.
  • Grinnellephantitis this weekend of Sep 11/12. 60 minutes suffices. Mac Field.
    • Times (9-4pm)
    • All you needed to know about Ultimate in one minute …
      • It’s like American or Unamerican Football, except with no contact and with a frisbee, and the inability to run with a ball.
      • Your goal is to get the roundish item in the end zone.
      • End zones are on opposite sides of the field.

Upcoming work

Some notes from Wednesday’s lab

What did you learn from the traces? (foo vs. bar; baz vs. qux)

  • Sometimes we can write conditional-like expressions more concisely without using conditionals. E.g., (if TEST #t #f) is a long way of writing TEST.
  • Conditional tracing is a bit different than other tracing; we don’t evaluate all the parameters to if; we only evaluate the first and then use that to decide whether to use the second or third.
  • “I’m feeling more confident at tracing.”

Q&A

How do we document values. E.g., if I defined a red-circle.

;;; red-circle : image?
;;; A medium-sized red circle with a black outline
(define red-circle
  (overlay (circle 40 'outline 'black)
           (circle 40 'solid 'red)))

Why do computer scientists use foo and bar (and baz and qux)?

There are multiple hypotheses.

Some claim it comes from the WWII military term “fubar”, “fouled up beyond all recognition”.

But others observe that “foo” predates WWII, appearing in a Daffy Duck cartoon, the Smokey Stover comic strip, and elsewhere.

In any case, these are the “metasyntactic variables”

Could we trace something else with conditionals that suggests why it’s important that we not evaluate all the parameters?

Sure.

;;; In my world, anything divided by zero is 1.
(define strange-divide
  (lambda (x y)
    (if (zero? y) 1 (/ x y))))

;     (strange-divide 2 3)
; --> (if (zero? 3) 1 (/ 2 3))
;     ; Evaluate the test
; --> (if #f 1 (/ 2 3))
;     ; The test is false, so move on to the alternate (parameter 3 of if)
; --> (/ 2 3)
;     ; Parentheses!  Evaluate the 2, evaluate the 3, do the division
; --> 2/3

;     (strange-divide 2 0)
; --> (if (zero? 0) 1 (/ 2 0))
;     ; Evaluate the test
; --> (if #t 1 (/ 2 0))
;     ; The test is true, so move on to the consequent (parameter 2)
; --> 1
;     We're done

; Suppose we used the normal evaluation strategy
;     (strange-divide 2 0)
; --> (if (zero? 0) 1 (/ 2 0))
;     ; Evaluate the test
; --> (if #t 1 (/ 2 0))
;     ; Evaluate the (/ 2 0)
; --> Error message

Moral: if has a different evaluation strategy, which means you can have sometimes erroneous or otherwise problematic code in one side and use the condition to determine whether or not to run.

Does and do the same thing?

Yes. If the first parameter to and is #f, it stops immediately and returns false.

How should we trace and

Evaluate the first parameter

If it’s false, replace the and with #f

If the first parameter is true, replace (and #t ...) with (and ...).

Why does the autograder give 0.999999

It helps with grading later.

Can we start lab?

Yes

“Twenty minutes” became 45. Are you always so bad at estimating times?

Usually

Can I go to the bathroom?

You are adults, you can feel free to leave my classroom at any time. As long as you are respectful to your partners.

Lab, continues

  • If you weren’t here on Wednesday, we’ll find you a place. (n/a)
  • If your partner from Wednesday is missing, we’ll find you a new partner. (decided to work with partner over the weekend; yay Self-Gov)

Some notes from Sam

  • Yes, you will have to write a lot of conditions for median-of-3. (Well, that’s at least one solution.)
  • (define is-even? (lambda (x) (if (zero? (remainder x 2)) #t #f))) is correct but also inelegant.
    • Refer back to foo/bar.
  • (define is-even-integer? (lambda (x) (if (integer? x) (if (zero? (remainder x 2) #t #f)) #f))) is also both correct and inelegant.
    • Use is-even? rather than repeating its body.
    • Refer back to baz/qux for simplification.
    • Note also that the order of testing is important.
  • How to write median-of-3 without conditionals (define median-of-3 (lambda (x y z) (- (+ x y z) (min x y z) (max x y z))))
  • Can you write both-even? with only one call to is-even? (and no calls to remainder).
    • As in (define (both-even? x y) (is-even? (some-function-of x y))).