In this video, I'm going to talk about the next form of data definiton, which is
called an interval. So this is really just an example how to
design data, and data driven templates problem.
I've got the seat num starter file open and because this is a how to design data
problem I'm going to put the how to design data definitions recipe here off
to the right and over in my broswer window I've got the how to design data
recipe page open. Back at the problem.
So, imagine we're designing a program to manage ticket sales at a theater, and we
want to represent the seat number in a row, and each row has 32 seats.
So, it's kind of a boring theater. That's what this comment here means, it's
a perfectly rectangular theater. And we need to represent a seat number.
So if you think about that a row looks kind of like this, and the seat numbers
can be something like one or two or three, all the way up to 32.
Since these are seat numbers and not indexes in a string, let's use the normal
kind of numbers that people like, where they start at one and go to 32.
So the question is, that's the information, information is numbers from
one to 32. That are going to be seat numbers.
How are we going to represent that? Well, if we go over to the How to Design
Data webpage, and again, this is a webpage that you should read ahead of
time. I'm going to be using it kind of in a
mode where I already know how to use it. I'm going to scroll down, to this table
that says when the form of the information to be represented.
Is atomic. Well this is atomic.
Seat numbers are going to be something like one or two.
And that's atomic. But I'm going to keep reading because
sometimes there's something more specific.
And here it is. When it's numbers within a certain range.
And that's exactly what this case is. It's numbers like one, two, three all the
way up to thirty two. So, it's numbers within a certain range.
And there's a kind of data definition for that called an interval.
So, here we go to intervals. Now, an interval type comment looks
something like this. There's a type name and then we're going
to say a kind of number and then a notation for talking about the range Let
me jump back over here to Dr. Racket and do it and I'll talk about that
notation as I go. So let's see, we're going to say
something like, SeatNum is, and then these are numbers, integers.
Between 1 and 32. And what's going with these square
brackets is, in square brackets mean inclusive.
So this means integer is starting at one, including one.
Going up to 32 including 32. Let me just show you some variations on
this so you'll understand all of what we can say.
For one thing, this could be natural, because natural numbers are integers that
start at, at 0. So I could say natural here.
Natural one to 32, integer one to 32, they're the same.
But some other variations. For example if I said something like
number. 132 and that's going to be a lot more
things because numbers include real numbers, like 1.3 and 1.4 and 1.5 and we
don't have that with seat numbers. We really need natural numbers or
integers here. If I said natural square bracket 1 comma
32 round bracket then that wouldn't include the 32 because the round bracket
means up to but not included. So square means inclusive and round means
not inclusive. So there we go.
There's our type comment. Now I've got to say interpret this.
So what's the interpretation here. Well lets see.
These are seat numbers in a row and I might know some more information about
that. In particular what I might know is that
one and 32 are aisle seats. Or I might know something else about the
theatre. But anything that would help me
understand exactly what the numbers 132 and all the numbers in between mean is
what I would put in the interpretation. And now let me make some examples.
I'll say seat number one and I'll just call that one.
And seat number two might be 12. And seat number three might be 32.
And the reasons we going to do multiple examples in this case.
sometimes its nice to have examples that illustrate specific thing.
So this might be an asile and this is a middle and this is an aisle.
You always want to have at least one example and you should have other
examples if they're illustrated, and again as I said when we were doing the
city name data definition. As data definitions become richer,
examples will become more important and more useful.
So we got the type command the interpretation in the examples.
Now we have to do the template. So I'll start the template like this
define fn-for-seat-num, there is going to be some body there, and also inside the
template process like this, like saying template rules used; now I am set to do
the template I'll go back over here to the data definition page.
I'll follow this link to the data-driven templates page.
And now I've gotta look down and find this form of data, and interval.
Intervals are atomic non-distinct. So we're going to end up using the same
template rule here that we used For city name, which is just open parenthesis dot,
dot, dot in the parameter name. So we go back here, we say, we say open
parenthesis dot, dot, dot. The parameter name which is seat-num.
And here we say, atomic non distinct and always like to put after the colon here,
exactly what part the of type comment it was caused us to do that.
You'll see it's starting in the next data definition we do.
When data definitions gets more complicated, why we're doing that.
There we go, that data definition is complete.
I'm going do everything well formed. I'll put a comment like that there.
So have a comment like that. And we're good to go.