Lumaktaw sa pangunahing content

Mga Post

Ipinapakita ang mga post mula sa Enero, 2018

EP: 5 - Functions

Part 5. Functions Functions allow us to have different output each time, functions make up the bulk of programming, and they are also reusable. Here is how we can use functions to help us design programs In this code here, we have a traffic light image using the above primitive. There is something wrong in this code, we are reusing the circle primitive and we are only changing the color, In programming, repeating the same lines of code makes the code bigger and more complicated to read. Programmers generally refactor and simplify code using functions, which allows code to be reusable. A function definition is the same as mathematical functions, which takes an input, processes it and outputs the information. Examples of math functions that you have learned in high school algebra. Given f(x) = 2 * x; f(2) = 2 * 2 = 4 f(6) = 2 * 6 = 12 The output varies on what we input, and this is also the concept that is applied to programming, although very abstract....

EP: 4 - Constants

Part 4 - Constants Constants are types of data that cannot be changed by external means. It also allows us to easily replace variables should requirements change. let's look at this example. Let's say that we want to make an Image. Here, we have defined WIDTH and HEIGHT as constants which points to 400 and 600 respectively. The convention for declaring constants are Upper case in most programming languages. Constant declarations do not produce any output. If we define WIDTH and HEIGHT in our code, this would be replaced by 400 and 600 respectively. Here is how racket evaluate constants. (define WIDTH 400) (define HEIGHT 600) ;CONSTANT DECLARATIONS (* WIDTH HEIGHT) (* 400 HEIGHT) (* 400 600) Racket replaces the constants with their respective values. Interesting enough, we can use constants with Images. Go to  http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html  and scroll down where you would find the cat image. Co...

EP 3. Strings and Images in Racket

Part 3. Strings and Images Racket allows us to build strings, which are just a sequence of characters, and images, which are images. No new evaluation techniques are needed here as it works the same way as primitive calls.  a typical string looks like this, as it is represented in any major programming language "I am a string" the value of the strings are the strings themselves, they can be considered expressions. To append or combine a string together, we use the string-append primitive. Of course since we deal with names, we just need to add a space string operand. string-append takes some number of string operands to combine. Now let us look at the limitations of certain primitives, lets look at these 2 values there. The string "123" and the number 123 are different, "123" has a double quote which indicates a string, while 123 is obviously a number. We can use the addition primitive to add 2 numbers, as we ...

EP 2. Racket Evaluation

Part 2. Racket Evaluation In this part, we are going to evaluate racket code. Racket has a specific order, like PEMDAS in basic arithmetic, on how we evaluate code. take a look at this example (+ 2 (* 3 4) (- (+ 1 2) 3)) run this expression in dr. racket and we have 14. But how does racket evaluate? Look at the outer parenthesis, it first look at the primitive ( + 2 (* 3 4) (- (+ 1 2) 3)) The primitive here is the plus sign. It is called as an operator so it will see that it is an addition operator, what which values we will add to?     2. Look at the operands ( +   2 (* 3 4) (- (+ 1 2) 3) ) The colors blue, violet and orange are the operands To evaluate a primitive call has 2 rules 1. all operands have to be reduced to values 2. apply primitive to values So it has some recursion to it. Now we look at each operand the 2 operand is already a value, we need not touch it, look at the second operand   (* 3 4) This Needs...

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