[BLANK_AUDIO].
In this video, I'm going to work through a relatively straightforward how to
design functions problem. So this video would be a really good
chance for you to practice what you saw in the HTDF full speed and slow motion
videos. Just get the starter file and start
working the problem yourself. And every now and then, run the video to
kind of catch up to where you are in the problem, so that you could see that
you're doing it kind of the way that I'm doing it in the video myself.
>> Okay. This first function is going to be
simple, a lot like [UNKNOWN]. You need to design a function called Yell
that consumes strings like hello and produces strings like hello bang, where
the exclamation mark has been added to the end.
So let's see, the signature of this function is it consumes string and it
produces string. And what it's supposed to do is produce
[SOUND] string with bang added to end of supplied string.
And that's a little cumbersome. purpose statements are often cumbersome
the first time you write it, let's see if you can do better than that.
What if we just say, add bang to the end of s, where s is the name of the
parameter in the stub. So that's simple.
We'll add bang to the end of s. Okay, let's write a check-expect.
Check-expect. Yell with hello and better produce hello
bang like that. And check-expect yell with bye.
It better produce bye, bang. Like that.
Now we run the test, run the check-expects.
And both are failing but the key thing is that both are running.
So that tells me that they are well formed.
So I'll just ignore the fact that they're failing for now.
I really just want to know if they were running.
And now what we'll do is we'll comment out this stub and we'll label it
[UNKNOWN] stub. And let's see.
The template for this function is dif-, is defined yell of s.
Body of the template is dot dot dot s. What I'm going to do is select the
template, make a copy of it. Paste a copy here.
Comment out the template and label it as being the template.
Later in the course, you won't have to leave the template behind.
But for now we find that it's helpful. There is the template.
And now I need to edit it. And, oh yeah, what this function does is
it produces a new string by adding bang to the end of s.
And so that's just going to be string-append S and bang like that.
Now, we'll want it again and both tests passed.
So there you go. That's the design of the yell function
following the HTDF recipe.