1 00:00:06,377 --> 00:00:08,634 [BLANK_AUDIO]. We're looking at bump-up-starter.rkt, and 2 00:00:08,634 --> 00:00:12,960 the problem here is to use the LetterGrade data definition below. 3 00:00:12,960 --> 00:00:17,250 Here it is here, and design a function that consumes a letter grade and produces 4 00:00:17,250 --> 00:00:22,872 the next highest letter grade. So we're going to call your function 5 00:00:22,872 --> 00:00:25,670 bump-up. So here is the data definition that we 6 00:00:25,670 --> 00:00:28,840 did before. Listen, I want to make an important point 7 00:00:28,840 --> 00:00:32,250 here. In these examples, we have a single data 8 00:00:32,250 --> 00:00:35,170 definition and a single function that goes with it. 9 00:00:35,170 --> 00:00:41,170 In normal programs, they tend to be many functions that consume data defined by a 10 00:00:41,170 --> 00:00:44,690 single data definition. So the ratio of functions to data 11 00:00:44,690 --> 00:00:48,690 definitions is usually pretty high. Don't think that you have to design a 12 00:00:48,690 --> 00:00:51,180 separate data definition for each function. 13 00:00:51,180 --> 00:00:55,780 In this case, there might be a function called bump-up for the nice professors 14 00:00:55,780 --> 00:00:58,845 and bump-down for the not nice professors. 15 00:00:58,845 --> 00:01:03,900 And is honor role, and all of those would all consume letter grade. 16 00:01:03,900 --> 00:01:06,810 There would just be a single copy of the letter grade data definition. 17 00:01:06,810 --> 00:01:10,880 In fact, we'd put it in this part of the file called data definitions. 18 00:01:10,880 --> 00:01:12,798 And then, there would be multiple functions down here. 19 00:01:12,798 --> 00:01:16,380 So now let's get on with designing this function. 20 00:01:16,380 --> 00:01:22,180 And I'm going to do something here, which is I'm going to put a mistake in the 21 00:01:22,180 --> 00:01:26,330 template. And I'm doing this to show you why it is 22 00:01:26,330 --> 00:01:30,910 we are always careful to run templates when we do data definitions, to make sure 23 00:01:30,910 --> 00:01:34,080 they're well formed. So I'm just going to inject that error 24 00:01:34,080 --> 00:01:36,680 right there, and we'll see what happens as we go on. 25 00:01:36,680 --> 00:01:39,660 Now try to forget it. So here we go. 26 00:01:39,660 --> 00:01:47,090 We're going to assume a letter grade. [SOUND] And we've got to produce the next 27 00:01:47,090 --> 00:01:49,530 highest letter grade. So we're also going to produce a letter 28 00:01:49,530 --> 00:01:54,706 grade. [SOUND] Produce next highest letter 29 00:01:54,706 --> 00:02:03,110 grade. Now, there's an ambiguity in this problem 30 00:02:03,110 --> 00:02:06,400 statement, and we're going to start to have a little more ambiguity in our 31 00:02:06,400 --> 00:02:10,186 problem statements, because remember, design is about going from ill-formed 32 00:02:10,186 --> 00:02:14,150 problems to well-structured solutions. And the ambiguity here is what do we do 33 00:02:14,150 --> 00:02:15,793 with A? Okay. 34 00:02:15,793 --> 00:02:20,809 There isn't anything higher than A, so we might just put in parens, no change for 35 00:02:20,809 --> 00:02:25,387 A. [SOUND] Now we need a stub. 36 00:02:25,387 --> 00:02:35,895 [SOUND] We'll run that just to make sure everything is well formed. 37 00:02:35,895 --> 00:02:40,185 Now remember because this template is complimented out, we're not seeing that 38 00:02:40,185 --> 00:02:45,872 error there. So now, let's see. 39 00:02:45,872 --> 00:02:48,540 Here we go. Now we need examples. 40 00:02:48,540 --> 00:02:53,664 If you go to the How to Design Data page and you scroll down to the part about 41 00:02:53,664 --> 00:02:59,124 enumerations, [SOUND] it basically says that you need to have at least as many 42 00:02:59,124 --> 00:03:07,925 tests as there are cases in the enumeration, which is what makes sense. 43 00:03:07,925 --> 00:03:12,730 Going back to the code, this enumeration has three cases A, B, and C. 44 00:03:12,730 --> 00:03:19,190 It makes sense that we're going to have three examples, [SOUND] check expect of 45 00:03:19,190 --> 00:03:22,000 A. We just decided that was going to produce 46 00:03:22,000 --> 00:03:25,529 A. And now when you two more. 47 00:03:25,529 --> 00:03:29,950 [SOUND] I'll just copy this one and edit it because they're all going to look 48 00:03:29,950 --> 00:03:33,225 pretty close to the same. Let's see, there's bump-up of A, there's 49 00:03:33,225 --> 00:03:37,490 bump-up of B, and there's bump-up of C. We already said that bump-up of A 50 00:03:37,490 --> 00:03:40,440 produces A. Bump-up of B produces A. 51 00:03:40,440 --> 00:03:44,760 Bump up of c produces B. That's our examples. 52 00:03:44,760 --> 00:03:48,870 We'll run them to make sure they're well-formed. 53 00:03:48,870 --> 00:03:52,014 And they are. But one is they're all running, one's not 54 00:03:52,014 --> 00:03:54,050 passing. We knew that. 55 00:03:54,050 --> 00:03:55,670 Okay. Now, we need the template. 56 00:03:55,670 --> 00:04:05,146 So, I will comment out this stub/g. [SOUND] I'll say that we use template 57 00:04:05,146 --> 00:04:16,150 from LetterGrade. I'll go up here and get this template. 58 00:04:16,150 --> 00:04:22,920 I'll copy it down. I'll rename it. 59 00:04:22,920 --> 00:04:25,870 And now, well, this is quite simple, this function. 60 00:04:25,870 --> 00:04:29,830 [SOUND] If we are bumping up an A, we get an A. 61 00:04:29,830 --> 00:04:33,780 If we're bumping up a B, we get a B. And if we're bumping up [INAUDIBLE], if 62 00:04:33,780 --> 00:04:40,457 we're bumping up a B, we get an A. And if we're bumping a C, we get a B. 63 00:04:40,457 --> 00:04:48,830 And now, I'll run it. Oh, and I'm getting this error, l: this 64 00:04:48,830 --> 00:04:53,348 variable is not defined. And Racket highlights it for me. 65 00:04:53,348 --> 00:04:57,159 And now I have to figure out what this error is. 66 00:04:57,159 --> 00:05:03,545 And I see oh, yeah this should have been an lg because the parameter name is lg. 67 00:05:03,545 --> 00:05:07,230 So I'll put an lg there. [BLANK_AUDIO] And now you see, the reason 68 00:05:07,230 --> 00:05:11,060 I got this error is because the error was in the template. 69 00:05:11,060 --> 00:05:14,930 This is why we check the well-formedness of the templates before we comment them 70 00:05:14,930 --> 00:05:18,370 out, is to get as many errors as possible out of them. 71 00:05:18,370 --> 00:05:23,970 Because, otherwise, every time you copy the template, you get the error copied, 72 00:05:23,970 --> 00:05:26,100 right? It's not good to copy code with mistakes 73 00:05:26,100 --> 00:05:30,920 in it. Back down here, lets run this. 74 00:05:30,920 --> 00:05:34,580 All three tests passed. So in this case, because we had 75 00:05:34,580 --> 00:05:37,780 enumeration and we got not only the structure of the template, but we got the 76 00:05:37,780 --> 00:05:40,930 structure of the examples. Because for an enumeration, you should 77 00:05:40,930 --> 00:05:46,190 have at least one test for each case. In this case, it doesn't make sense to 78 00:05:46,190 --> 00:05:50,800 have any more than three. But it is possible, in certain cases, for 79 00:05:50,800 --> 00:05:55,850 functions that consume more than just the enumeration to need more tests than there 80 00:05:55,850 --> 00:06:00,530 are number of cases in the enumeration. We'll see examples of that in later weeks.