1 00:00:06,260 --> 00:00:09,410 In this video, I'm going to talk about the next form of data definiton, which is 2 00:00:09,410 --> 00:00:14,084 called an interval. So this is really just an example how to 3 00:00:14,084 --> 00:00:17,950 design data, and data driven templates problem. 4 00:00:17,950 --> 00:00:22,622 I've got the seat num starter file open and because this is a how to design data 5 00:00:22,622 --> 00:00:27,148 problem I'm going to put the how to design data definitions recipe here off 6 00:00:27,148 --> 00:00:31,455 to the right and over in my broswer window I've got the how to design data 7 00:00:31,455 --> 00:00:38,010 recipe page open. Back at the problem. 8 00:00:38,010 --> 00:00:41,829 So, imagine we're designing a program to manage ticket sales at a theater, and we 9 00:00:41,829 --> 00:00:46,650 want to represent the seat number in a row, and each row has 32 seats. 10 00:00:46,650 --> 00:00:49,610 So, it's kind of a boring theater. That's what this comment here means, it's 11 00:00:49,610 --> 00:00:53,475 a perfectly rectangular theater. And we need to represent a seat number. 12 00:00:53,475 --> 00:00:57,440 So if you think about that a row looks kind of like this, and the seat numbers 13 00:00:57,440 --> 00:01:02,800 can be something like one or two or three, all the way up to 32. 14 00:01:02,800 --> 00:01:06,576 Since these are seat numbers and not indexes in a string, let's use the normal 15 00:01:06,576 --> 00:01:11,600 kind of numbers that people like, where they start at one and go to 32. 16 00:01:11,600 --> 00:01:15,260 So the question is, that's the information, information is numbers from 17 00:01:15,260 --> 00:01:18,590 one to 32. That are going to be seat numbers. 18 00:01:18,590 --> 00:01:22,510 How are we going to represent that? Well, if we go over to the How to Design 19 00:01:22,510 --> 00:01:25,460 Data webpage, and again, this is a webpage that you should read ahead of 20 00:01:25,460 --> 00:01:28,368 time. I'm going to be using it kind of in a 21 00:01:28,368 --> 00:01:33,401 mode where I already know how to use it. I'm going to scroll down, to this table 22 00:01:33,401 --> 00:01:38,808 that says when the form of the information to be represented. 23 00:01:40,030 --> 00:01:43,580 Is atomic. Well this is atomic. 24 00:01:43,580 --> 00:01:46,280 Seat numbers are going to be something like one or two. 25 00:01:46,280 --> 00:01:48,692 And that's atomic. But I'm going to keep reading because 26 00:01:48,692 --> 00:01:51,060 sometimes there's something more specific. 27 00:01:52,830 --> 00:01:56,328 And here it is. When it's numbers within a certain range. 28 00:01:56,328 --> 00:02:00,708 And that's exactly what this case is. It's numbers like one, two, three all the 29 00:02:00,708 --> 00:02:05,460 way up to thirty two. So, it's numbers within a certain range. 30 00:02:05,460 --> 00:02:08,336 And there's a kind of data definition for that called an interval. 31 00:02:08,336 --> 00:02:12,420 So, here we go to intervals. Now, an interval type comment looks 32 00:02:12,420 --> 00:02:15,950 something like this. There's a type name and then we're going 33 00:02:15,950 --> 00:02:19,550 to say a kind of number and then a notation for talking about the range Let 34 00:02:19,550 --> 00:02:24,450 me jump back over here to Dr. Racket and do it and I'll talk about that 35 00:02:24,450 --> 00:02:29,408 notation as I go. So let's see, we're going to say 36 00:02:29,408 --> 00:02:36,000 something like, SeatNum is, and then these are numbers, integers. 37 00:02:36,000 --> 00:02:44,174 Between 1 and 32. And what's going with these square 38 00:02:44,174 --> 00:02:48,870 brackets is, in square brackets mean inclusive. 39 00:02:48,870 --> 00:02:52,420 So this means integer is starting at one, including one. 40 00:02:52,420 --> 00:02:58,020 Going up to 32 including 32. Let me just show you some variations on 41 00:02:58,020 --> 00:03:01,660 this so you'll understand all of what we can say. 42 00:03:01,660 --> 00:03:05,881 For one thing, this could be natural, because natural numbers are integers that 43 00:03:05,881 --> 00:03:09,103 start at, at 0. So I could say natural here. 44 00:03:09,103 --> 00:03:12,980 Natural one to 32, integer one to 32, they're the same. 45 00:03:12,980 --> 00:03:16,640 But some other variations. For example if I said something like 46 00:03:16,640 --> 00:03:18,737 number. 132 and that's going to be a lot more 47 00:03:18,737 --> 00:03:20,879 things because numbers include real numbers, like 1.3 and 1.4 and 1.5 and we 48 00:03:20,879 --> 00:03:25,414 don't have that with seat numbers. We really need natural numbers or 49 00:03:25,414 --> 00:03:31,140 integers here. If I said natural square bracket 1 comma 50 00:03:31,140 --> 00:03:38,820 32 round bracket then that wouldn't include the 32 because the round bracket 51 00:03:38,820 --> 00:03:46,885 means up to but not included. So square means inclusive and round means 52 00:03:46,885 --> 00:03:50,080 not inclusive. So there we go. 53 00:03:50,080 --> 00:03:56,980 There's our type comment. Now I've got to say interpret this. 54 00:03:56,980 --> 00:04:02,380 So what's the interpretation here. Well lets see. 55 00:04:02,380 --> 00:04:05,976 These are seat numbers in a row and I might know some more information about 56 00:04:05,976 --> 00:04:10,394 that. In particular what I might know is that 57 00:04:10,394 --> 00:04:20,061 one and 32 are aisle seats. Or I might know something else about the 58 00:04:20,061 --> 00:04:25,740 theatre. But anything that would help me 59 00:04:25,740 --> 00:04:28,990 understand exactly what the numbers 132 and all the numbers in between mean is 60 00:04:28,990 --> 00:04:35,340 what I would put in the interpretation. And now let me make some examples. 61 00:04:35,340 --> 00:04:40,180 I'll say seat number one and I'll just call that one. 62 00:04:40,180 --> 00:04:46,340 And seat number two might be 12. And seat number three might be 32. 63 00:04:46,340 --> 00:04:50,484 And the reasons we going to do multiple examples in this case. 64 00:04:50,484 --> 00:04:55,190 sometimes its nice to have examples that illustrate specific thing. 65 00:04:55,190 --> 00:05:00,542 So this might be an asile and this is a middle and this is an aisle. 66 00:05:00,542 --> 00:05:05,273 You always want to have at least one example and you should have other 67 00:05:05,273 --> 00:05:10,419 examples if they're illustrated, and again as I said when we were doing the 68 00:05:10,419 --> 00:05:17,470 city name data definition. As data definitions become richer, 69 00:05:17,470 --> 00:05:22,420 examples will become more important and more useful. 70 00:05:22,420 --> 00:05:25,081 So we got the type command the interpretation in the examples. 71 00:05:25,081 --> 00:05:30,200 Now we have to do the template. So I'll start the template like this 72 00:05:30,200 --> 00:05:37,000 define fn-for-seat-num, there is going to be some body there, and also inside the 73 00:05:37,000 --> 00:05:43,500 template process like this, like saying template rules used; now I am set to do 74 00:05:43,500 --> 00:05:53,550 the template I'll go back over here to the data definition page. 75 00:05:53,550 --> 00:05:56,140 I'll follow this link to the data-driven templates page. 76 00:05:56,140 --> 00:06:03,888 And now I've gotta look down and find this form of data, and interval. 77 00:06:03,888 --> 00:06:10,349 Intervals are atomic non-distinct. So we're going to end up using the same 78 00:06:10,349 --> 00:06:15,857 template rule here that we used For city name, which is just open parenthesis dot, 79 00:06:15,857 --> 00:06:23,190 dot, dot in the parameter name. So we go back here, we say, we say open 80 00:06:23,190 --> 00:06:30,926 parenthesis dot, dot, dot. The parameter name which is seat-num. 81 00:06:32,070 --> 00:06:39,000 And here we say, atomic non distinct and always like to put after the colon here, 82 00:06:39,000 --> 00:06:47,730 exactly what part the of type comment it was caused us to do that. 83 00:06:47,730 --> 00:06:50,920 You'll see it's starting in the next data definition we do. 84 00:06:50,920 --> 00:06:54,741 When data definitions gets more complicated, why we're doing that. 85 00:06:54,741 --> 00:06:57,850 There we go, that data definition is complete. 86 00:06:57,850 --> 00:07:04,092 I'm going do everything well formed. I'll put a comment like that there. 87 00:07:04,092 --> 00:07:14,278 So have a comment like that. And we're good to go.