Lumaktaw sa pangunahing content

EP: 14 - Enumeration Data Definitions

EP. 14 - Enumeration Data Definitions

Enumeration data definitions are used to represent information that has 2 or more distinct values.

For example, We are designing a data definition for student grades. The grade can be A, B or C.

In this problem domain, the grade can have 3 different values, which is A, B or C. Since we have a data which can have 3 distinct values, it makes sense that we use Enumeration for our template to make our data definitions.

When making the Type Comment of the Enumeration Data Definition. We need to enumerate each distinct value.


 When interpreting enumeration, this tends to be straightforward.


 On enumerations, we do not need to have examples since they are redundant. The examples are already in our type comment.

For the enumeration template, we need to make an if-conditions that would cover all the distinct values that we have here, in a Condition and the Corresponding expression. 

Since the individual distinct value now is considered Atomic. We can refer to the Atomic Distinct Value as reference on designing our template relevant to the data definition.

The data values are strings, so we will use the template appropriate for strings.

 And this is the data definition template for Enumeration. Enumerations are data that have distinct values.

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: 19 - big-bang Mechanism

Part 19. big-bang We are using Dr. Racket to design interactive programs, from this day forward, this is going to be very complicated. Imagine we have 2 interactive programs, one that counts down from 10 to 0 and some animation of a cat walking in the screen. These programs are interactive by just pressing the space key, the program restarts. These interactive programs change state and it affects the program behavior. On the countdown program, it generates a number from 10 to 0 every 1 second. It is also the same with the cat program, it just changes the x coordinate of the cat every miliseconds. These are 2 different functions, now how can we combine these 2 functions. We combine them by using Dr. Rackets big-bang primitive. (big-bang 0           (on-tick next-cat)           (to-draw render-cat)) We use 0 as the initial world state, then on every tick, we get the next x coordinate, we pass it to the render c...