TOPIC of the Week: Composing Definitions (for Identifiers, Outputs, Functions without Design, Non predetermined Functions, and more!)
Introduction:
Hi everyone, and welcome back! :)
Today (Friday) officially ends week 3 of CSC104, and thus begins my weekly update!
Wow! I honestly can't believe how quickly this week has flown by! Nevertheless, I have some new updates for you. :D
In terms of the Question to be answered later on, which was: "What programming language is being used to code for text (i.e. Dr. Racket, Java, etc.)??", I have yet to ask my Instructor about it, so I will most likely have an answer for you next week! :)
So, let's see what I have learned this week.
Getting into the "SLOG" of Things:
This week (Week #3) in class, we discussed the quite difficult to understand, and daunting topic of DEFINING our own codes on Dr. Racket! :S I must admit, I was somewhat (*very*) intimidated, but Professor Heap reassured the class that we would not have to define functions on the upcoming Quiz (which I did today, actually)! Thank goodness! Whew! :P
Although I'm still fairly intimidated with defining functions in the interactions pane, I am completely up for the challenge because I want to master Dr. Racket! :)
1) We learned how to make programming much easier for ourselves by defining certain "identifiers" to stand for certain words. This makes programming much easier in Dr. Racket because we don't have to CONSTANTLY copy and paste images, write out long numbers OR sentences! It's wonderful! :) Also,we were shown how to place images beside or on top of each other. Some of the images I used (a can of pop, for instance) came out VERY interesting to look at, to say the least!
The class was shown how to essentially create Dr. Racket "Inception" by creating a function application with other function applications WITHIN them! Wow! In performing this exercise, we learned to calculate the sum of, say 49 divided by 7 with 23 x 90, appending (adding) the first, say five, characters (**SEE string- append function from last week's post!) of "forty- three" to the first, say three, characters of thirty- seven to produce forty-thi
Also, we learned to horizontally and vertically flip an image (flip: horizontal (p)) or (flip: vertically (p)) and place it either next to or on top of itself.
3) Then, we learned to define a function referred to as shrinking. This function first produces the original function, then places a half (1/2) scaled cope of that original image beside itself. As well, we defined a function called mirror-rosette, which produced the mirror image -going from left to right- of rosette. Rosette being another function we assigned an image, words, or numbers to. Again, rosette is a great tool used to make us lazy computer scientists that much more lazy!!! :D
4) The next part showed us how to create functions STEP-BY-STEP. :) I found this particularly useful, as breaking the steps down made the logic behind the steps MUCH easier. So, thanks, Sir! :) An example gave was to create a function using the words "half-flip". These two words take one image as input, and scales the SAME image to half of its size; hence the "half" in the function. Also, this function flips the image horizontally.
Question to be answered later on (hopefully):
For the "half- flip" function, how can I flip it vertically, and how do I know this particular function is flipping the image horizontally?
A short description and explanation of what we learned in each section of defining Dr. Racket functions:
1) Defining Identifiers (to stand for Dr. Racket Values) and Domestication for Dr. Racket:
- Setting identifiers to stand for values by typing the following in the interactions pane:
(require picturing-programs)
(define jumbo (p)) --> type the word "jumbo" into the task pane and press enter to display only the image of the picture defined with the word "jumbo"
Similarly, this can be done for numbers:
(require picturing-programs)
(define lucky 1.612131256) --> type the word "lucky" into the task pane and press enter to display only the number defined with the word "lucky"
Also, this operation can be done with long sentences:
(require picturing-programs)
(define words "Today is the most wonderful day ever because it is a Friday. I was born on a Friday, and this day of the week signifies the start to the weekend.") --> type the word "words" into the task pane and press enter to display the words in commas.
**REMINDER**: Once you have defined your values, DON'T FORGET to click "run" on the upper right corner of the Dr. Racket page
- To see each STEP performed in defining each of the values, click STEP. This will show you the steps in defining the function when you HIGHLIGHT the definitions you would like to see the steps for. You can select jump to--> beginning or end of selected area to narrow-down your steps even further and save time searching through the ENTIRE definition for a select word. :)
- The former (STEPS involved in defining each function) is useful because you can find the inverse of, say, "lucky", by typing the following into the interactions pane:
(define forgot-lucky lucky), you would type "forgot-lucky" in the task pane OR (define inverse-lucky (/ 1 lucky), you would simply type "inverse-lucky" in the task pane OR (define small-jumbo (scale 1/3 jumbo), you would type "small-jumbo" in the task pane--> scales the image to 1/3 of its original size.
- You can define a new identifier to see what the first, say, 10 characters of the sentence defined by "words" is:
(define opening-words (substring words 0 10) --> "Today is the"
- Defining the functions further by typing:
(define mirror-small-(p)) (flip-horizontal small-jumbo)--> type "mirror-small-(p)" to evaluate to a new value
I enjoyed learning about how to simplify my life, even if it was only in one aspect (computers/ programming). I find these operations very useful in that they save a lot of time, and effort. Convenience is key in Computer Science! :)
ALL CREDIT goes to the YouTube channel "Danny Heap", who is my Professor:
2) Composing Output as Input:
BEFORE I begin to explain what I learned in this section, I must admit that I was baffled, and did not fully understand this section; however, I will explain it as best I can, and will update this post next week when I understand it fully (I will be asking my Professor about this section!).
Question to be answered later on:
How to define outputs as inputs?
I will continue this post tomorrow.