CS2613/journal/_src/posts/2022-09-12-lab-two.md
Isaac Shoebottom b70d452341 Correct tags
2022-10-12 11:11:47 -03:00

3.3 KiB

Title: Lab Two
Date: 2022-09-12T08:30:00
Tags: cs2613, lab, git, racket

In this lab we learned more about git, and using racket to draw shapes

Additional Git Information

Git grep was useful in finding any file with the given content I am looking for without having to open all of them to find what I am looking for. This would have been useful to know before I removed the social media links without grep.

Git status was useful in showing the status of my changes, and the added and untracked files.

I also used raco frog --clean to keep my git repository clean before committing.

Git log showed me the history of my project's commits, which was useful in reminding myself what I had done the previous lab

Racket Introduction

Running racket from the command line was not too hard and the display bug was fixed by simply using the displayln function instead of display

DrRacket is a Racket IDE with a REPL. REPL stands for read-evaluate-print-loop, which is what the racket repl does.

In DrRacket, I used the circle function ((circle 10)), the rectangle function ((rectangle 10 20) and that the error that is given when you try to run a function with too many arguments. I also learned how to combine the output (append) the output of two functions together.

I learned how to define names for a specific function call, like saving the function (circle 10) as variable c. Appending the output of defined functions also works. For example (hc-append c c) would print (circle 10) twice.

You can also use this functionality to define functions, for example, give your define statement an argument and you can use that within the rest of the define statement. This is best explained by showing that (define (square n) (filled-rectangle n n)) will define a square by using the pre-existing filled rectangle function.

In racket you can create what are known as "local bindings" which are functions that are local (belong to) a parent function. You can define these individually with another define function, or to define them by using let or let*, with the latter letting later bindings use earlier bindings. Both of them let you define more than one binding at once.

It was also noted how identifiers were scoped within a language, with a function arguemnt being avialable throughout the function, and when a variable is not in scope, it does not "exist" so can therefor be defined again, like in this example

(define (rgb-series mk)
    (vc-appned
        (series (lamda (sz) (colorize (mk sz) "red")))
        (series (lamda (sz) (colorize (mk sz) "green")))
        (series (lamda (sz) (colorize (mk sz) "blue")))))

This shows that sz can be defined multiple times because within a given series each sz is only within the scope of the series, and each sz is therefor unique.

Lists in Racket are very important and this can be seen through the way functions map onto lists. As shown in the documentation you can map a list of squares to a colorize function which contains a list of colors. You can also apply things to lists.

Racket also features a module system, which is where you declare the set of the language you are working on with the #lang keyword. You can also import additional libraries with the require keyword. You can install modules from racket files or from the raco package manager that comes with Racket.