Warning! You are being recorded (and transcribed) (provided the technology is working correctly).
Approximate overview
Academic/Scholarly
Cultural
Peer
Wellness
Misc
This problem gave the most difficulty. So we’re going to talk through a similar problem.
First, let’s review what the two procedures do.
cut builds a procedure by “cutting out” parts of an expression. You
can also think about it as filling in some, but not all, parameters
to a procedure.compose (o) sequences unary procedures, creating a new procedure
that applies them right to left.Let’s consider an example.
(define rgb-fun-one
(lambda (color)
(rgb-subtract (rgb 255 255 255)
(rgb-darker
(rgb-darker
(rgb-subtract (rgb 255 255 255)
(rgb-lighter color)))))))
TPS: Describe in English what’s happening.
We can rewrite that to …
(define subtract-from-white
(lambda (color)
(rgb-subtract (rgb 255 255 255) color)))
(define rgb-fun-one
(o subtract-from-white rgb-darker rgb-darker subtract-from-white rgb-lighter))
Where’s the parameter to rgb-fun-one?
It’s implicit. The
osays “this is a function that appliesrgb-lighterto its parameter, the subtract-from-white to the result, then rgb-darker to the result, then rgb-darker to the new result, then subtract-from white.
Can we verify that it’s a procedure and that it works similarly?
> rgb-fun-one
#<procedure:...pkgs/csc151/hop.rkt:170:4>
> (rgb-fun-one (rgb 255 0 0))
.
Can we compose a procedure that needs multiple parameters?
Nope. You can’t compose it, at least not given how we’ve written compose.
For now, we only compose one-parameter (unary) procedures.
Let’s revisit subtract-from-white.
(define subtract-from-white
(lambda (color)
(rgb-subtract (rgb 255 255 255) color)))
``
This is a candidate for `cut`. Rewrite subtract-from-white using `cut`.
(define subtract-from-white (cut (rgb-subtract (rgb 255 255 255) <>)))
Once we have that, we can just shove the `cut` into our composition.
(define rgb-fun-one (o (cut (rgb-subtract (rgb 255 255 255) <>)) rgb-darker rgb-darker (cut (rgb-subtract (rgb 255 255 255) <>)) rgb-lighter))
Do we really need `subtract-from-white`?
> No. That was just to get us moving forward in thinking about the problem.
(Aka decomosition.)
Here's another example.
``
(define munge-shape
(lambda (shape)
(rotate
(beside (solid-square 10 "black")
(recolor (rotate (scale shape 2)
45)
"red"))
-45)))
What steps are there?
(cut (scale <> 2))(cut (rotate <> 45))(cut (recolor <> "red"))(cut (beside (solid-square 10 "black") <>))(cut (rotate <> -45))How do we turn those into Racket?
(define munge-shape
(o (cut (rotate <> -45))
(cut (beside (solid-square 10 "black") <>))
(cut (recolor <> "red"))
(cut (rotate <> 45))
(cut (scale <> 2))))
Other notes
cut on multiple procedures when we employ this
approach.How do we document the cut and composed procedures given that they don’t have explicit parameters?
We pretend they have parameters.
;;; (munge-shape shape) -> image?
;;; shape : image?
;;; Create a larger version of the shape with a diamond attached
;;; to its upper-left-hand-corner.
;;; (subtract-from-white color) -> rgb?
;;; color : rgb?
;;; Subtract `color` from `white`, computing the pseudo-complement
;;; of the color.
A hint: You are much better off writing a trivial procedure, like the following, than submitting nothing for part of the assignment.
(define solid-octagon
(lambda (side-length color)
(solid-square side-length color)))
This will probably pass the one-star tests, helping ensure that you get an R (which doesn’t require a token for the first resubmit) than an I (which does).
Many of you wrote something like the following for solid-pentagon.
(define solid-pentagon
(lambda (side-length color)
(solid-polygon (list (pt (real-part (make-polar (/ side-length (* 2 (sin (/ pi 5))))
(* 2/5 pi)))
(imag-part (make-polar (/ side-length (* 2 (sin (/ pi 5))))
(* 2/5 pi))))
(pt (real-part (make-polar (/ side-length (* 2 (sin (/ pi 5))))
(* 4/5 pi)))
(imag-part (make-polar (/ side-length (* 2 (sin (/ pi 5))))
(* 4/5 pi))))
(pt (real-part (make-polar (/ side-length (* 2 (sin (/ pi 5))))
(* 6/5 pi)))
(imag-part (make-polar (/ side-length (* 2 (sin (/ pi 5))))
(* 6/5 pi))))
(pt (real-part (make-polar (/ side-length (* 2 (sin (/ pi 5))))
(* 8/5 pi)))
(imag-part (make-polar (/ side-length (* 2 (sin (/ pi 5))))
(* 8/5 pi))))
(pt (real-part (make-polar (/ side-length (* 2 (sin (/ pi 5))))
(* 10/5 pi)))
(imag-part (make-polar (/ side-length (* 2 (sin (/ pi 5))))
(* 10/5 pi)))))
color)))
Isn’t the repetitious? What could you do to make it less so?
map, we could use that.](define solid-pentagon
(lambda (side-length color)
(alternate-solid-pentagon (/ side-length (* 2 (sin (/ pi 5)))) color)))
(define alternate-solid-pentagon
(lambda (radius color)
(solid-polygon (list (pt (real-part (make-polar radius
(* 2/5 pi)))
(imag-part (make-polar radius
(* 2/5 pi))))
(pt (real-part (make-polar radius
(* 4/5 pi)))
(imag-part (make-polar radius
(* 4/5 pi))))
(pt (real-part (make-polar radius
(* 6/5 pi)))
(imag-part (make-polar radius
(* 6/5 pi))))
(pt (real-part (make-polar radius
(* 8/5 pi)))
(imag-part (make-polar radius
(* 8/5 pi))))
(pt (real-part (make-polar radius
(* 10/5 pi)))
(imag-part (make-polar radius
(* 10/5 pi)))))
color)))
What do you see as the key concepts that this assignment is asking you to learn or develop?
Please think about big-picture issues and what we’ve been doing lately.
Without looking at any resources (e.g., readings, labs, your notes), write down everything you know that might be useful for this assignment.
This should really be a brain dump. Write procedures. Write procedure names.
Here's an example of a procedure where I change a color.
(define rgb-invert
(cut (rgb-subtract (rgb 255 255 255) <>)))
What resources (e.g., individual procedures you’ve written, readings, labs) will be helpful as you work on this assignment?
I’d like to see more notes on individual procedures. Now’s the time to look some up.
In the class notes for class 13 <https://rebelsky.cs.grinnell.edu/Courses/CSC151/2024Sp/eboards/eboard13>, we wrote a procedure that made colors "something". It looked like this.
(define rgb-fun-one (o (cut (rgb-subtract (rgb 255 255 255) <>)) rgb-darker rgb-darker (cut (rgb-subtract (rgb 255 255 255) <>)) rgb-lighter))
_How long do you expect this assignment to take?_
Please express this in hours, not days or weeks.
Questions
---------
### Administrative
Will Sam update tokens so that we can enter more?
> Sure. It's on my agenda for tonight.
### MP2
Can you give us a diagram for outlined right triangles?
> Sure. I'll add it to my agenda for tonight.
### MP3
### Lists
Can you go over the darker circles problem?
> Sure.
;;; (thickly-outlined-circle color) -> image? ;;; color : color? ;;; Make a thickly outlined circle of the specified color. (define thickly-outlined-circle (lambda (color) (overlay (outlined-circle 20 “black” 5) (solid-circle 20 color))))
(define rainbow-color-names (list “red” “orange” “yellow” “green” “blue” “indigo” “violet”))
b. Using `apply` and `map`, make a picture of seven outlined circles in darker versions of the rainbow colors (computed by using two calls to `rgb-darker`). Note that you'll need to convert the color names to RGB colors with `color-name->rgb` and then make them darker with two calls to `rgb-darker`.
What do we want to do to each color name?
* convert to an RGB
* then make it darker
* then make it darker
* then make it into a circle
It's an opportunity to compose. And map
(map (o thickly-outlined-circle rgb-darker rgb-darker color-name->rgb) rainbow-color-names)
(apply beside (map (o thickly-outlined-circle rgb-darker rgb-darker color-name->rgb) rainbow-color-names)) ```
When do we use apply?
When we have a procedure that expects a bunch of parameters and we’ve somehow managed to put all of those parameters into a list.
Most frequently, when we have a procedure that expects “as many parameters as you give it” and a list. We might apply
+,string-append,beside,above.