Lumaktaw sa pangunahing content

Attempting to learn programming theory EP 1. Dr Racket

Part 1. Starting Racket



    I am trying to attempt to enroll an MOOC which is How to Code, Simple Data on EDX. The university has given us an incubator project which is to make a software for language learning in mandarin.

    The main problem is that some of my teammates do not have self confidence in their abilities despite that they have made a functioning computer system. Hopefully, this course will teach them how to think more abstract which they will need to make their own computer systems. Most of them have imposter syndrome which would be detrimental to their progress, and some of them still want to live like teenagers, which is understandable since being an adult is boring as hell. I can relate, I would also want my free days back also. But tough luck, the arrow of time always moves forward and obvoiusly when they want to go to Manila for their OJT, well we have to finish the requirements of the University in the Incubator

    To entice my teammates to take the course, I will try to blog as I learn the MOOC, at least as an encouragement.

    The language to use here is Racket, which is a lisp variant, descended from one of the earliest programming languages along with COBOL, It has all the features of all programming languages, you learn that, and also the provided design theory in the course, you learn them all.

    According to the instructor, you must actually understand how the code works, not by just copying and pasting things without a care on what they represent. Hopefully, my advice would be heeded and they will be more confident of their Critical Thinking skills as they have presented with their capstone projects. 

    And yes, this has just become a Job, a major one at that. I can see why some would want to back out.

    I voluntarily took the role of a project lead, and would look into some project management tools, I am either considering gitlab for Source Control and Orangescrum for development. As an obviously inexperienced Project Manager, this would be the first time I would really handle a team. The teams I have handled back then are different, group members would literally have no contribution whatsoever, their loss. Now, it is warranted that all would participate, my teammates would be envious of the lightweight lifestyle of the interns in manila, understandably since they would be inexperienced while the rest of us would be already being baptized in fire.


While you may not use racket/lisp in the industry, this course will teach you to think critically, which we really need to complete the project.

Dr Racket Basics

    Install the IDE for Racket, called Dr Racket and when opened, it should select a language called beginning student language. This is the language that I will use in the course. For the introductory lesson, expressions are the topic.

Launch Dr. Racket, in most cases, there will be no language selected, you need to select a language.


To select a language, click the language menu and choose language
Select teaching languages and double click beginning student
At the lower left, it should show the highlighted yellow text




When opened, there are two windows, the top one is the Definitions area and the bottom one is the interaction area


  • Definitions area - Source Code
  • Interaction area - Inputs and Outputs


Now that we got this cleared, lets have a simple arithmetic
To add in racket we do this

(+ 3 4)

This evaluates to 7 after we run it.




These are what's called in racket, Expressions. and in turn it produces a Value. 

You still remember PEMDAS in Elementary math??? or maybe you hate math, then why did you take programming in the first place. Just joking, but math is pure logic and programming is just a form of abstract math if you look at it that way. There are inputs, processes and outputs.

Expressions can also be complicated, just like grade 1 math.

(+ 3 (* 2 3))




obviously * is multiplication, any grade 1 student can solve it. Racket works like this. It evaluates the parenthesis first, remember pemdas rule. Heres another example so that you would get it

(/ 12 (* 2 3))




That is division.

So to summarize, how to make expressions in racket to output some value?

(<primitive> <expression>...)

where expression can be any number of expressions. Note that some primitives have a limited number of expressions.

This is how to comment in racket, start the line with a semicolon, since we have no expressions present, it will not output


To get the square and square root of a number, do this


sqr returns the square of the number while sqrt returns the root. Arithmetic functions, sqr and sqrt are primitives.

The instructor has given an exercise at this point and I will solve them by using my critical thinking, but please try to solve on your own.



I will only solve the first question on the lectures so that you will also have an initiative to take the MOOC. Programming is about solving problems just like math but more abstract, can't do that? Quit programming.

Okay, Critical Thinking powers activate


  1. Alright, Question is read, to find the third side of a right triangle, you need the pythagorean theorem. The hypotenuse is missing.
  2. Remember that the parentheses is evaluated, but in what order
  3. I can also nest parenthesis like a math problem, this takes me back to my Grade 3 algebra
  4. Alright, I need to add the square of 2 given sides in the adjacent and the opposite
(+ (sqr 3) (sqr 4))

As seen here, I am adding the results of the square of 3 and 4, hey, this is just like elementary math but i will need to get the root of the sum of the squares like in the math symbol

(sqrt (+ (sqr 3) (sqr 4)))

By any convention, If i remember my trigonometry, this should be 5

drumroll please



This is just simple PEMDAS, but instead of mathematical symbols, its words. 

Just like math, it requires a little thinking. 

Little fun note before we go, what about roots of not perfect squares, this comes up.

the #i represents that it is an inexact number, it is infinite but computers have finite memory so it is estimated as closer to 1.41

this was the first episode of using racket to evaluate expressions, good day.

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...