EBoard 04: Procedures, subroutines, and such

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]
  • Quiz [~5 min]
  • Interpreting Racket [~10 min]
  • Lab [~50 min]

Administrative stuff

Notes and News

  • Evening tutoring will be available 3-5 p.m. Sundays and 8-10 p.m. Sundays through Thursdays in the tutoring channel on the CS team.
  • I hope you are coping through the uncertainty of today’s US elections.
    • The College has sent out a list of resources. Let me know if you need a copy.
    • If you find that you can’t get work done, let me know and I’ll adjust appropriately (no tokens required).
  • For clarity: Mini-projects are due Wednesday evenings at 10:30 p.m. CST.
    • Redos are due the following week at the same time.
  • I’m happy to answer questions at the start of class. However, if you can ask some questions in the Questions and Answers channel, it will likely make things a bit more efficient.
  • We’ve seen some issues with screen sharing on Macs with the latest version of Teams. Turning off the new interface might help. If not, “drive” with the other person’s screen (i.e., tell them what to type) or find another way to screen share (e.g., the G-word thing).
  • I’m still working on figuring out Gradescope. Sorry for the confusion on Mini-Project 1 and the delay in getting quiz 1 graded.
  • Sorry that I’m not available during the normal work time for some of you. Note that I do have insomnia, so you will, on occasion, get a response. I don’t have a good solution beyond that; but remember that for most issues, you can also rely on classmates.
    • I can try to set up tags for the people in different timezones
  • Building community?
    • Don’t make fun of your students. (Damn!)
    • Discuss current issues in the context of your class. (Damn!)
    • Breakout groups / small groups (Yay!)
    • Allow chatter in the chat. (Or Discord or Teams)
    • For students: Encourage others who are quieter.
    • Acknowledge the circumstances.
    • Have awesome fun because CS is awesomely fun.

Upcoming activities

I will post details to the Announcements channel.

You can respond to recordings for the tokens, provided you do so within one week of the event. I would, however, prefer that you attend “live”.

Your response is a reflective paragraph, sent via email.

You can also suggest events.

  • Noon, Thursday: Convocation! (+1 token)
    • You’ll get my lecture about Convocation on Wednesday.
  • 5pm, Thursday: Learn about the CS major (+1 token)

Upcoming work

I’ll try to include this list of upcoming work each day. Your colleagues have created a Discord Channel that they will demo for you.

  • Reading writeup for today (due 8:00 a.m. this morning; a few minutes ago!)
  • Lab writeup for today (due Wednesday 8 a.m. on Gradescope; ideally before the end of class today)
  • Readings for Wednesday (responses to questions due Wednesday 8 a.m. on Gradescope)
  • Mini-project 1 (due Wednesday at 10:30 p.m. CST)
  • I’m still working on getting the “auto graders” working on Gradescope. You may see some errors from the autograder. You can ignore it.
  • We will have another short (5 min) quiz today.
    • For today, you won’t be producing code.
    • You can use your own notes.
    • You can use the course Web site.
    • In quizzes with code, you can use DrRacket to check your answer.
      • Enter and save in the quiz, first.
      • Then check in DrRacket.
      • For most quizzes, the focus is generally conceptual more than syntactic; it’s okay if the Racket syntax is not quite correct.
      • In that sense, DrRacket can be your enemy as much as your friend.
      • When we get to learning assessments, you will be expected to produce code with correct syntax.
    • You can ask questions in advance.
    • You may not use other people.
    • You may not discuss it in the Discord server (or GroupMe or …).

Attendance

  • Our wonderful mentors will take attendance by looking at the the list of also-wonderful people here.

Further examples of M vs E

Meets expectations

(above (circle 20 'solid "black")
       (beside (circle 20 'solid "black")
               (circle 20 'solid "black"))
       (beside (circle 20 'solid "black")
               (circle 20 'solid "black")
               (circle 20 'solid "black")))

Also meets expectations, even though it doesn’t work.

(above circle 20 'solid "black")
       beside (circle 20 'solid "black")
               (circle 20 'solid "black"))
       (beside (circle 20 'solid "black")
               (circle 20 'solid "black")
               (circle 20 'solid "black"))))))))

Better (probably the best you can do right now)

(define ball (circle 20 'solid "black"))
(above ball
       (beside ball ball)
       (beside ball ball ball))

Overkill (beyond what you can do right now)

(define ball (circle 20 'solid "black"))
(define row-of-balls 
  (lambda (n)
    (if (= n 1)
        ball
        (apply beside (make-list n ball)))))
(define pyramid
  (lambda (rows)
    (apply above (map row-of-balls (cdr (iota (+ 1 rows)))))))

Q&A

Clarification: Are quizzes satisfactory / non-satisfactory?

Yes

Why do you need zero-parameter procedures?

They may depend on things in the “environment” that change.

Sometimes we want computations done delayed.

We can “protect” some of the variables within the body from the outside world, avoiding confusion (and renaming of variables).

Randomness is something that will change.

Why is above not defined?

Make sure to do the (require 2htdp/image). Sam will check in during lab.

What do quizzes cover?

Generally, the prior day (and before).

Likely, a problem related to the prior day’s lab.

Can you reflect an image over an axis? I couldn’t find it in the big image documentation.

Sam will try to figure it out.

Or the smart students notes that flip-horizontal and flip-vertical work.

Can we nest procedure calls?

Yes.

Quiz

Bring up readings in your browser.

(Don’t bother opening DrRacket.)

Go to the Quiz in Gradescope.

Five minutes (more or less).

Interpreting Racket

The big question: How does DrRacket (or any Racket interpreter) evaluate the code you enter?

  • Like most programs, the DrRacket interpreter deals with both data and instructions (an algorithm).

  • The most important data is a “table” that maps names to values.

      > (define x 10)
      > (define y "Hello")
      ; x: 10
      ; y: "Hello"
    
  • Each time Racket sees a define, it updates the table.

      > (define x 11)
      ; x: 11
      ; y: "Hello"
      > (define y (* x x))
      ; y: 121
    
  • For (define NAME EXP), the evaluator evaluates the expression and then updates the table to associate the name with the expression.

  • You can only define a name once in the definitions pane.

  • However, you can re-define a name in the interactions pane. (Not generally encouraged.) [Variables in Racket don’t vary.]

  • Racket evaluates expressions one at a time, in order, inside-out. (Yay sequencing!)

      (display "Hello")
      (display (+ 2 3))
      ; Does the "Hello" first
      ; Then adds 2 and 3
      ; Then displays the sum
    
  • The big question: How does it evaluate an expression? The answer: It depends on the kind of expression.

  • Expression type 1: A number, like 123. Treat that like the number.

  • Expression type 2: A string, like "Hello". Treat it verbatim (as a string).

      > "Hello"
      "Hello"
      > "(+ 1 2)"
      "(+ 1 2)"
      > (string-length "(+ 1 2)")
      7
    
  • Expression type 3: Symbols, like `solid. Similar to strings, but no string-length.

  • Expression type 4: A sequence of letters and numbers, like x or are-you-bored-yet? Looks them up in the table. If it’s in the table (something we’ve defined), gives the corresponding value. Otherwise, issues an error message.

  • Expression type 5: Something with an open parenthesis. Depends on what you see next
    • a. A procedure name (name-of-proc params)
    • b. The define, as in (define NAME EXP)
    • c. lambda (which means “procedure”), as in (lambda (PARAMS) BODY)
  • Expression type 5a: Evaluate all of the params, then runs the procedure (using the mental/substitutive model from the reading)

  • Expression type 5b: Evaluates the expression and then updates the table.

  • Expression type 5c: Does nothing (other than noting that it’s a procedure); just represents a set of instructions that can be computed later.

      > (define f (lambda (x) (* x (+ x x))))
      ; f: procedure with inputs x and body (* x (+ x x))
    
  • Expression type 5a, revisited: If the procedure is a user-defined procedure, it evaluates all of the params, then substitutes each for the corresponding input in the body, then evaluates body.

      ; f: procedure with inputs x and body (* x (+ x x))
      > (f (+ 3 4))
      ; First, evaluate the (+ 3 4) = 7
      ; --> (f 7)
      ; --> (* 7 (+ 7 7))
      ; --> (* 7 14)
      ; --> 98
    

Summary

  • Racket evaluates inside-out. Yes.
  • When there are multiple parameters, it evaluates
    • Left to right
    • Right to right
    • Some arbitrary order [Scheme]
    • All at once
    • Don’t make assumptions. Ideally, it shouldn’t matter.

Q&A

What should we do if there are multiple expressions to evaluate?

Pick an order. (Left to right is always good.)

Lab

New pairs! Let’s hope Sam can get the code to run.

You will not be able to finish in class. Sorry. You may finish on your own or arrange a time to meet with you partner later.

  1. Sam (well, Sam using a computer program he wrote) assigns groups.

  2. First person in the group goes to the Lab Sessions channel, clicks the camera (or something equivalent) and then “Meet Now”. Please get the channel right. We won’t see you in other channels.

  3. Add a subject. “Group # (Names)”, such as “Group 1 (SamR & JohnG)” Please get the group name right. It makes it much easier for us.

  4. Click “Meet Now”.

  5. Invite the other members of the group.

  6. Other members of the group join. (Today, you can start discussions once you have two in the group. Generally, you’ll wait until everyone is there.)

  7. Discuss/work/whatever.

There are four problems. You should submit at least the first three by the end of class. Sam will warn you when there are ten minutes left in class so that you can decide whether to submit the first three problems or try to do all four together.

Debrief

We won’t have time, but I like to leave the potential there.