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

1.4 KiB

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

In this lab I learned about Racket recursion techniques.

Rainbow example

I had great difficulty in getting the rainbow code to work. I ended up with a working definition but not much time to do much else. My function follows:

(define (rainbow2 p)
  (define (color-mapper gr-obj color-list)
    (cond
      [(empty? color-list) empty]
      [else (cons(colorize gr-obj (first color-list))
        (color-mapper gr-obj (rest color-list)))]))
        (color-mapper p (list "red" "orange" "yellow" "green" "blue" "purple")))

This defines a function called rainbow 2, which then defines another function called color mapper. color mapper checks if there is an empty list, and if so, ends. If there is not an empty list, it calls the colorize function with the first item in the list, with the passed in graphical object. If then recursively does this until the list is empty, since each recursive call removes an item from the start of the list. In the end you get a set of colored objects in the order of the function call at the end of the definition of rainbow 2.

Conclusion

I did not do much of the lab as assigned, because of my difficulty in making the program. My understanding of how my program works after getting it working will help me in getting future labs done on time