Approximate overview
Events
Other good things
Can you explain when?
Sure.
The form is
(when (test) consequent1 consequent2 ...).
whenis likeif, but without the alternate.
whenalso differs fromifin 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,
whendoes nothing else, returns nothing.
If the test does hold, it does all of the consequents in sequence, returning the value of the last one.
whenis 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
whenfor 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.
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.The autograder is not working correctly. Sorry!
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->fgindependently 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.
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”.