Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"


0 (0 Likes / 0 Dislikes)
GREGOR KICZALES: So as I said in the introduction, we're going to design some great programs in this course-- some games, some animations, some information visualization, some web programs. Really great stuff. But the thing is, you got to walk before you can run. And in the same way, we've got to learn some basic building blocks before we can build these great programs. So that's what we're going to do for the next few videos is learn some basic building blocks out of which we're going to build bigger programs. We're going to try to do it quickly because it isn't that exciting. But we're going to try not to do it too quickly because we want everybody to be able to stay with us. So if maybe you've programmed before and this video seems a little slow, then feel free to speed it up. But most of the people who take this class haven't programmed before, so we're going to try to go a good speed for that. And if the video's a little too fast, then you can replay the part of the video that you need to replay. As we go through it, I'd encourage you to have DrRacket open and follow along with the examples that I'm going to do. So here we go. When we start Racket for the first time, we have to tell it what language we're going to use. Your Racket may have started up already saying, Beginning student language, down in this lower left corner. And if it did, then you're all set. You don't need to do anything. But if it didn't, then go to the Language menu. Say Choose Language. Make sure the How To Design Program part is opened up and choose Beginning Student. The way you'll get to this menu will be slightly different in Windows, of course, but you're going to want to go to the Language menu to do that. So go to the Language menu and select Beginning Student Language, and then you'll be all set to go. Now that that's done, we can get started. The top part of Racket here is called the Definitions Area, and the bottom part is called the Interaction Area. We're going to start by working up in the Definitions Area. And we're going to start by writing a simple arithmetic expression. I'll just put plus 3 4. This is how we're going to say to add three to four in the beginning student language. And if I ask DrRacket to run that short program, it will. And down here, it tells me that the result of that program is 7, which isn't so surprising. Adding 3 to 4 should produce 7. This is what's called an expression. And in the bottom window, we have what's called a value. And the way Racket is working is we give it expressions, and it evaluates the expression to produce the value. Expressions can be more complicated. For example, we could say plus 3 times 2 3. And we can run that program, and no surprise, it produces 9. We can make expressions that are even more complicated than that or use other primitive operators. Here we'll just divide 12 by times 2 3. And unsurprisingly, that will give us 2. So what we've seen so far is that the rule for the way we form an expression is open parenthesis, the name of a primitive operator, like plus or times or slash, and then any number of other expressions followed by a close parenthesis. And there's another rule that says expressions can be actual values. So numbers themselves can be expressions. Let me show you another thing we can do. We could take all of this, and if we say to Racket Comment That Out with Semicolons, then it'll put a semicolon in front of each of those lines. And what that tells Racket is, for now, it should ignore everything on a line after the first semicolon. So if I would run this program now, as far as Racket's concerned, there's no expressions in there at all. And so there's no values that come out. Let me tell you about two more primitive operations on numbers, and then I'll ask you to do an exercise. The first one is sqr. We call it square. And if I take square of 3-- and I'll show you another one here at the same time-- square root of 16, and I'll run these two. And what you're seeing is that square squares the number, and square root produces the square root of a number. OK. We've seen how to form expressions. And we've seen a number of primitives that operate on numbers, primitives like plus, and times, and divide, and minus, and square, and square root. What I'd like to do now is give you an exercise that you can use to help reinforce what we've learned so far. We'll have exercises like this throughout the videos in this course. I'd like to encourage you to take the time to do them just to test your understanding of what's come so far. So here's the exercise. I've got it in a separate file. And let me just explain this big box. Racket has a thing called a comment box, which you can actually add to a file yourself under the Insert menu. And the way to think of a comment box is, see this semicolon here? It's basically saying everything in the box is a comment. And what's also neat about Racket is that you can put images in the middle of files. That's just an image that I cut and pasted. At any rate, here's the exercise. Go ahead and work on it. Write the expression.

Video Details

Duration: 5 minutes and 36 seconds
Language: English
License: Dotsub - Standard License
Genre: None
Views: 6
Posted by: artusllaja on Sep 30, 2015


Caption and Translate

    Sign In/Register for Dotsub to translate this video.