1 00:00:07,430 --> 00:00:10,760 In this video, I'm going to talk about how you can discover more primitives, 2 00:00:10,760 --> 00:00:16,810 than the ones I cover in the videos. In the Beginning Student Language, 3 00:00:16,810 --> 00:00:20,630 there's far too many primitives for you to learn them all and far, far too many 4 00:00:20,630 --> 00:00:24,045 for us to cover them in the videos. So you need to be able to discover 5 00:00:24,045 --> 00:00:27,250 primitives on your own. And in other programming languages, there 6 00:00:27,250 --> 00:00:30,430 will be even more primitives that you need to be able to discover on your own. 7 00:00:31,600 --> 00:00:34,330 So what I want to talk about, is two general techniques you can use for 8 00:00:34,330 --> 00:00:38,520 discovering primitives. Now the first one, you're going to laugh 9 00:00:38,520 --> 00:00:41,810 at this, the first one is actually to make a lucky guess. 10 00:00:43,280 --> 00:00:46,790 You may think that's crazy, but it turns out that what happens, after you've been 11 00:00:46,790 --> 00:00:51,080 programming in a language for awhile, is you start to get a pretty good sense of 12 00:00:51,080 --> 00:00:55,470 what the naming conventions are. And it turns out you do manage to guess 13 00:00:55,470 --> 00:00:58,490 the name of a new primitive, more often than you might think. 14 00:01:00,040 --> 00:01:05,250 Let me show you how that works. Imagine now we go back to where we were, 15 00:01:05,250 --> 00:01:12,845 in the strings and images video. I know there's circle, rectangle, and 16 00:01:12,845 --> 00:01:15,320 text. I might say, well gee, I wonder if 17 00:01:15,320 --> 00:01:17,698 there's something called triangle, and I could just try it. 18 00:01:17,698 --> 00:01:21,070 And I guess triangle must have some kind of size. 19 00:01:21,070 --> 00:01:26,880 I'll just put in a number. And it probably has something like a fill 20 00:01:26,880 --> 00:01:30,490 or a color, so let's just say solid, and let's say purple. 21 00:01:30,490 --> 00:01:35,990 Again, I'm just trying this to see if it works. 22 00:01:35,990 --> 00:01:39,620 And sure enough, it does seem to work. At this point, I might wonder well, what 23 00:01:39,620 --> 00:01:43,770 exactly is that number 40? And then I can go up here to triangle, 24 00:01:43,770 --> 00:01:47,510 click on it it, and on my Mac, I'm going to Ctrl + Click. 25 00:01:47,510 --> 00:01:51,882 On Windows, you would Right-click, and say Search and Help Desk for Triangle. 26 00:01:51,882 --> 00:01:58,290 And this is going to bring up the DrRacket documentation for triangle. 27 00:01:58,290 --> 00:02:02,015 And I want the one from 2htdp image, so I'm always going to select the one from 28 00:02:02,015 --> 00:02:08,520 2htdp image. And it says that the first number is the 29 00:02:08,520 --> 00:02:13,340 side length. So I know that 40 is this side length 30 00:02:13,340 --> 00:02:17,400 right along there. That's the 40. 31 00:02:17,400 --> 00:02:20,130 So you can guess, and often you can guess right. 32 00:02:20,130 --> 00:02:23,150 That's the first technique for discovering new primitives is to make a 33 00:02:23,150 --> 00:02:26,396 good guess. Another good trick for discovering the 34 00:02:26,396 --> 00:02:32,250 name of new primitive's is called search and scroll, or look up and scroll. 35 00:02:32,250 --> 00:02:36,940 Imagine that what I'm doing is I'm writing some expressions that in my 36 00:02:36,940 --> 00:02:41,305 Racket, like this one, divide 3 by 4. Now, if I run that, of course, I get 37 00:02:41,305 --> 00:02:44,250 0.75. But maybe what I really like to do is 38 00:02:44,250 --> 00:02:48,390 round that to the nearest whole number, like 1 in this case. 39 00:02:48,390 --> 00:02:51,970 There must be a function in Racket to help me do that. 40 00:02:51,970 --> 00:02:55,100 So here's how the trick works. I find a place in the code where there's 41 00:02:55,100 --> 00:02:58,930 a related function, in this case divide. Divide's kind of like round. 42 00:02:58,930 --> 00:03:04,880 It operates on numbers, and I control click on top of divide or in Windows, I 43 00:03:04,880 --> 00:03:09,300 right click. And then I pick the menu item Search in 44 00:03:09,300 --> 00:03:13,810 Help Desk for "/". Now, the thing is, Racket supports a lot 45 00:03:13,810 --> 00:03:15,854 of different languages. Okay? 46 00:03:15,854 --> 00:03:20,610 I want to choose the documentation for slash, from hdtp beginner. 47 00:03:20,610 --> 00:03:26,039 I want to choose this line of it here. And so I want to click on that slash 48 00:03:26,039 --> 00:03:33,120 right there, and that will take me to the documentation for this version of divide. 49 00:03:33,120 --> 00:03:36,080 And here I am and goodness gracious, there's a whole bunch of functions here 50 00:03:36,080 --> 00:03:39,294 that look like they operate on numbers, divide, less than, greater than. 51 00:03:39,294 --> 00:03:42,360 And what I'm going to do, is I'm going to scroll through these, and I'm going to 52 00:03:42,360 --> 00:03:46,380 try not to pay too much attention into the list, because there's a lot of these 53 00:03:46,380 --> 00:03:49,507 functions. So I'm just kind of scrolling, scrolling, 54 00:03:49,507 --> 00:03:54,002 scrolling my way through this list. I need to not get lost in all these 55 00:03:54,002 --> 00:03:56,980 functions, or else my head is going to explode, but I'm scrolling, scrolling, 56 00:03:56,980 --> 00:03:59,180 scrolling. And eventually, after there's a whole lot 57 00:03:59,180 --> 00:04:07,190 of scrolling in this case, there are lots of functions that operate on numbers. 58 00:04:07,190 --> 00:04:12,640 I will come to a function that is the one that I need in this case, and here it is, 59 00:04:12,640 --> 00:04:17,880 round. And round does what I want to do, it 60 00:04:17,880 --> 00:04:24,190 rounds a real number to an integer. So now I've got what I need. 61 00:04:24,190 --> 00:04:30,010 I go back to Racket. I put round around the previous 62 00:04:30,010 --> 00:04:32,160 expression. Ha, ha, ha. 63 00:04:32,160 --> 00:04:36,610 I run that and I get 1, which was what I was looking for. 64 00:04:37,710 --> 00:04:41,770 So the trick here is, to look up the documentation for a related function, and 65 00:04:41,770 --> 00:04:45,700 then scroll around looking for the thing you want, without getting lost in all the 66 00:04:45,700 --> 00:04:48,380 very, very many functions, that Racket provides. 67 00:04:50,760 --> 00:04:53,870 So that's two ways you can discover new primitives. 68 00:04:53,870 --> 00:04:58,520 You can either guess, and you'd be surprised how often you get lucky. 69 00:04:58,520 --> 00:05:02,720 Or you can look up the documentation for an existing primitives, and scroll around 70 00:05:02,720 --> 00:05:08,070 to find related primitives. As you program more and more, you'll get 71 00:05:08,070 --> 00:05:11,300 to know more and more primitives, and you'll be able guess lucky more often. 72 00:05:13,370 --> 00:05:16,965 You'll also going to see that programming environments, that's editors like 73 00:05:16,965 --> 00:05:22,450 DrRacket, have tools that help you guess more quickly, and we'll look at some of 74 00:05:22,450 --> 00:05:23,790 those in later weeks in the course.