Warning! You are being recorded and transcribed, provided the technology is working correctly.
We are back to the standard start-of-class procedure.
Approximate optimistic overview
Scholarly
Artistic
Multicultural
Peer
Musical, theatric, sporting, and academic events involving this section’s students are welcome.
Wellness
Misc
These do not earn tokens, but are worth your consideration.
Do I have to enter something to get a token for a mentor session?
Yes, mentor sessions require the same reflective paragraph as any other token events.
How do I tell how many tokens I have?
When I get the paperwork up to date, I’ll let you know.
Can you explain how I submit a redo?
Update your program to address the concerns raised in the first submission.
Submit it to make sure it passes all the tests (or as many tests as you’re satisfied passing). If it doesn’t pass tests at first, keep fixing and resubmitting until you’ve achieved a desired level. (Feel free to ask questions along the way.)
Once you’ve reached that level, submit both your updated .rkt file and a
CHANGES.txt
file that summarizes the changes you’ve made.
I don’t think we have covered using symbols much in this class yet, is there an example of how it can be used in a procedure?
We will and up using symbols either (a) with existing procedures that use symbols, or (b) when we want to compare them to each other.
Could you elaborate on using symbols “to provide a mnemonic value to a procedure”?
We’ve been using strings for most of our mnemonic values, but here’s one.
(solid-square 25 'blue)
.
How can you turn a string that has “non-numerical” characters &
numerical characters into a list of just the numbers. (e.g.,
("200/100/30")
-> '(200 100 30)
)
Isn’t that part of MP3?
You could use
string-split
to break the string apart. You can usestring->number
to convert each part.
> (string-split "200/100/30" "/")
'("200" "100" "30")
> (map string->number (string-split "200/100/30" "/"))
'(200 100 30)
What is the difference between 'a
, "a"
, and a
?
'a
is a symbol. Its primary purpose is for comparing to other symbols.
"a"
is a string. We can compare it to other strings. We can also find its length, extract substrings, append it to other strings, etc.
a
is an identifier. It names something. (Or doesn’t, if you haven’t used it withdefine
.)
Could we go over rgb-cyclic-subtract
?
Sure.
remainder
will be your friend.
For positive numbers,
(remainder (+ val 256) 256)
is the same as(remainder val 256)
.
Could we go over gamma-correct-component
?
Sure.
Basic idea: Gamma correction makes images lighter or darker in a “sensible” way.
Each component of an RGB color is between 0 and 255.
We want to convert them to a number in the range 0-1. (Divide by 255.)
We then take that number and compute
(expt num gamma)
. Ifgamma
is 1/2, we take the square root ofnum
, ifgamma
is2
, we squarenum
.
The result is also between 0 and 1.
Convert it back to an a number between 0 and 255. Multiply by 255 (and then round).
Exponents below 1 will make it lighter and exponents above 1 will make it darker.
When should you use cut
vs. composition?
You generally use
cut
when you’re calling another procedure and filling in some of the parameters, but not all of them.
(define blue-square (lambda (size) (solid-square size 'blue)))
(define blue-square (cut (solid-square <> 'blue)))
If you’re calling multiple one-parameter procedures in sequence, you will often want to use composition.
(pixel-map (lambda (color) (hsv->rgb (hsv-transformation (rgb->hsv color)))) (image-load "kitten.jpg"))
(pixel-map (o hsv->rgb hsv-transformation rgb->hsv) (image-load "kitten.jpg"))
Why can’t I use (max 1 (cut (- <> 1)))
?
Because
max
needs numbers, not procedures.
Let’s break down your steps. First you want to subtract 1.
(cut (- <> 1))
. Then you want to take the max of 1 and that result.(cut (max 1 <>))
. We have two procedures that you want to do in sequence, so we’ll use composition.
(o (cut (max 1 <>)) (cut (- <> 1)))