Lumaktaw sa pangunahing content

EP: 15 - Itemization Data Definition

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.

  1. Not yet started
  2. from 10 to 1 seconds until midnight
  3. Complete
This is like the countdown clock in TV.

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.




 Now that we have the full interpretation. Insert some examples.

 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.

  1. If a given subclass is the last subclass of it's type, you can just reduce to test the guard (for dynamic languages)
  2. If all remaining are cases of a given type. Remove all the guards.
Templates help us structure the function that we will be making.

Mga Komento

Mga sikat na post sa blog na ito

Problem Solving using HtDF method

Problem Solving In this problem, we will use the HtDF method to create a function. Problem:  Design a function that pluralizes a given word. (Pluralize means to convert the word to its plural form.) For simplicity you may assume that just adding s is enough to pluralize a word. Here is the problem that we need to convert into a function. We need to do it systematically using the HtDF method. First we need the signature, recall that the signature will tell us what is the input and expected output. A word is the input and output of the function, and we can represent words, which is just a sequence of characters if you think about it, like a String. So the signature of the function is ;;String -> String Then we will need to know what is the function's purpose, we can look at the specifications to know the purpose. It says that the word is pluralized in the process "assumption that adding s at the end is the pluralized form of the word". Ther...

EP: 18 - HtDF with Itemization

Part 18. HtDF with Itemization From the Countdown Display definition that we have made earlier, we are going to make a function out of it. We have to output an image depending on the state of the countdown.  Here is the Signature, Purpose and Stub. It is recommended to run the code often, the earlier we detect bugs, the better. We need some examples. For tests on itemizations, we need to have as many tests as there are cases. Also, if we have an interval, we have to test points of variance. For the Interval, there is not much variance in the seconds before midnight so it is okay to have only one test for that. There is a primitive called text which converts text to an image, we can also use number->string to convert a number into a string datatype. Note that when we are devising tests, we are already working out the behavior of the function before we start coding. Now we get the template and start creating the function body.  ...

EP: 9 - What not to do when designing functions

Part 9. Errors when designing functions. Mistakes can be made when designing functions. Here are common mistakes when using the HtDF method. 1. Do not repeat the Signature when making the purpose. The signature only shows us the Input and Output of a function, it does not say anything about its purpose. The purpose asks the question on what we do with the parameters and how can it generate the output. 2. Make sure the test is consistent with the purpose, should the test comes up wrong, either check the test itself with the purpose, signature or check the function body. Tests can also fail, take a deep hard look on what is causing that problem, there is a chance that the test is wrong so check it also.