[BLANK_AUDIO]. We're looking at bump-up-starter.rkt, and
the problem here is to use the LetterGrade data definition below.
Here it is here, and design a function that consumes a letter grade and produces
the next highest letter grade. So we're going to call your function
bump-up. So here is the data definition that we
did before. Listen, I want to make an important point
here. In these examples, we have a single data
definition and a single function that goes with it.
In normal programs, they tend to be many functions that consume data defined by a
single data definition. So the ratio of functions to data
definitions is usually pretty high. Don't think that you have to design a
separate data definition for each function.
In this case, there might be a function called bump-up for the nice professors
and bump-down for the not nice professors.
And is honor role, and all of those would all consume letter grade.
There would just be a single copy of the letter grade data definition.
In fact, we'd put it in this part of the file called data definitions.
And then, there would be multiple functions down here.
So now let's get on with designing this function.
And I'm going to do something here, which is I'm going to put a mistake in the
template. And I'm doing this to show you why it is
we are always careful to run templates when we do data definitions, to make sure
they're well formed. So I'm just going to inject that error
right there, and we'll see what happens as we go on.
Now try to forget it. So here we go.
We're going to assume a letter grade. [SOUND] And we've got to produce the next
highest letter grade. So we're also going to produce a letter
grade. [SOUND] Produce next highest letter
grade. Now, there's an ambiguity in this problem
statement, and we're going to start to have a little more ambiguity in our
problem statements, because remember, design is about going from ill-formed
problems to well-structured solutions. And the ambiguity here is what do we do
with A? Okay.
There isn't anything higher than A, so we might just put in parens, no change for
A. [SOUND] Now we need a stub.
[SOUND] We'll run that just to make sure everything is well formed.
Now remember because this template is complimented out, we're not seeing that
error there. So now, let's see.
Here we go. Now we need examples.
If you go to the How to Design Data page and you scroll down to the part about
enumerations, [SOUND] it basically says that you need to have at least as many
tests as there are cases in the enumeration, which is what makes sense.
Going back to the code, this enumeration has three cases A, B, and C.
It makes sense that we're going to have three examples, [SOUND] check expect of
A. We just decided that was going to produce
A. And now when you two more.
[SOUND] I'll just copy this one and edit it because they're all going to look
pretty close to the same. Let's see, there's bump-up of A, there's
bump-up of B, and there's bump-up of C. We already said that bump-up of A
produces A. Bump-up of B produces A.
Bump up of c produces B. That's our examples.
We'll run them to make sure they're well-formed.
And they are. But one is they're all running, one's not
passing. We knew that.
Okay. Now, we need the template.
So, I will comment out this stub/g. [SOUND] I'll say that we use template
from LetterGrade. I'll go up here and get this template.
I'll copy it down. I'll rename it.
And now, well, this is quite simple, this function.
[SOUND] If we are bumping up an A, we get an A.
If we're bumping up a B, we get a B. And if we're bumping up [INAUDIBLE], if
we're bumping up a B, we get an A. And if we're bumping a C, we get a B.
And now, I'll run it. Oh, and I'm getting this error, l: this
variable is not defined. And Racket highlights it for me.
And now I have to figure out what this error is.
And I see oh, yeah this should have been an lg because the parameter name is lg.
So I'll put an lg there. [BLANK_AUDIO] And now you see, the reason
I got this error is because the error was in the template.
This is why we check the well-formedness of the templates before we comment them
out, is to get as many errors as possible out of them.
Because, otherwise, every time you copy the template, you get the error copied,
right? It's not good to copy code with mistakes
in it. Back down here, lets run this.
All three tests passed. So in this case, because we had
enumeration and we got not only the structure of the template, but we got the
structure of the examples. Because for an enumeration, you should
have at least one test for each case. In this case, it doesn't make sense to
have any more than three. But it is possible, in certain cases, for
functions that consume more than just the enumeration to need more tests than there
are number of cases in the enumeration. We'll see examples of that in later weeks.