EBoard 26: Data Abstraction

Approximate overview

  • Admin
  • Vectors lab
  • Data abstraction lab

Administrative stuff

Introductory notes

  • Happy post-Halloween! I hope no one is going through sugar withdrawal.
  • Same places as last time.
  • I forget whether or not the autograders are working. Fingers crossed.
  • Congrats to our cross country team and to our ultra-marathoner

Upcoming activities

Events

  • Learning from CS Alums Tuesday at 2 p.m. in 3821: Alex Turner ‘16 or so. Effective Altruism, Grad School, and More.
  • Mentor session Tuesday at 8 p.m.
  • Mentor session Wednesday at 7 p.m.
  • Scholars’ Convocation Thursday at 11 am. Lara Janson ‘05. Humanizing Title IX: Centering Student Needs in Campus Community Responses to Sexual Violence.
  • Swimming vs. Luther, Saturday, 1 pm.

Other good things

  • Men’s Basketball vs. Coe, 7 pm Friday, Darby.
  • Are You Angry? in about two weeks.

Upcoming work

Q&A

Can you explain when?

Sure.

The form is (when (test) consequent1 consequent2 ...).

when is like if, but without the alternate.

when also differs from if in that you can have multiple consequents. That’s useful if you want to do more than one thing (e.g., update a vector and recurse).

If the test does not hold, when does nothing else, returns nothing.

If the test does hold, it does all of the consequents in sequence, returning the value of the last one.

when is useful for recursive procedures that have side effects (e.g., changing a vector, printing lots of values). First consequent: Change something. Second consequent: Recurse.

We also use when for checking preconditions (see Wednesday’s class).

You could also use (cond [(test) consequent1 consequent2 ...]).

Why use when rather than if and begin?

I don’t like begin. Don’t use it.

Vectors Lab

Preparation

  • Make sure that you have the correct lab page.
  • Get back to the place you were.
  • Review where you were.

Notes during class

We are trying to give you a variety of models of vector recursion.

  • tally-letters! is string recursion, but using an index. Our primary goal is to tally, but we return a vector.
  • vector-sum is vector recursion, returning a value.
  • my-vector-fill! is vector recursion, with the goal of a side effect.
  • vector-index-of returns a value and requires that we recurse from beginning to end.

End of lab

The autograder is not working correctly. Sorry!

Data Abstraction Lab

Preparation

  • You know the drill.

Notes during class

Does my name->fg have to work with every implementation of names?

Yes. But the whole point of this reading/lab is that you can write name->fg independently of the implementation.

How should I deal with Simon, who has no surname?

I’d use (or (name-surname person) ""), which gives you either the surname or the empty string.

Post lab notes

The data abstraction lab is OPTIONAL. Read through it. Be prepared to do an LA on it. But you need not turn it in. (If you want to turn it in to make up another lab, you can do so.)

Please go to https://sites.grinnell.edu and click “Request a Domain”.