Part 15. Itemization Data Definition
The Itemization Data Definition is what we use for information compromised of 2 different categories, at least one of each is not a distinct value.This data definition is quite complex.
As an example: Design a data definition for the current state of the countdown for the display, which falls in one of 3 categories.
- Not yet started
- from 10 to 1 seconds until midnight
- Complete
By looking at these states, the second one is not a distinct data value. Therefore this is not an enumeration. In this case, we will use the Itemization Data Definition.
We have to choose a datatype that fulfills the categories. For someone that has done strict programming style method for a long time now, Data consisting of multiple data types confuse my brain, but I think Lisp Based languages tend to be liberal about the types of parameters unlike the C family or it's influences. This is one of the thing that lisp blows my mind that I cannot comprehend that easily.
We also have to interpret these 3 categories also.
For values that are distinct, you have to be very specific with your examples that will help you in making functions.
Defining the template is next. The rule is similar to enumeration where we have to put an if-expression.
Then we can define the conditions whether they are distinct or non-distinct.
Different types of data in a single data definition is called mixed data. Some primitives do not play nice when a different type of data that is not meant to be passed as an argument is placed there.
For dynamically typed languages like racket or lisp, we can enforce type-checking to only accept the relevant datatype that is being passed.
For strictly typed languages, you can refactor your code to support a single datatype and create representations.
Itemizations and Large Enumerations can use else at the last condition, the reason is that it is guaranteed that when the options are already exhausted, the last one is guaranteed to be a string.
We can simplify this further, since we have only one Integer datatype here, we can just remove the AND condition where the two numbers are between 1 - 10. This is just a template to guide us.
There are 2 rules to handle mixed itemization.
- If a given subclass is the last subclass of it's type, you can just reduce to test the guard (for dynamic languages)
- If all remaining are cases of a given type. Remove all the guards.
Mga Komento
Mag-post ng isang Komento