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 "100/200/50" "/")
'("100" "200" "50")
> (string->number "100")
100
> (map string->number (string-split "100/200/50" "/"))
'(100 200 50)
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.
We want to subtract the corresponding components.
If we get a negative number, we add it to 256.
remainder
is your friend.
Helpful note: If
val
is a number in the range 0 … 255,(remainder (+ 256 val) 256)
is the same as(remainder val 256)
.
Could we go over gamma-correct-component
?
Sure.
Gamma correction makes images brighter or darker in a “sensible” way.
First step: Take each component (which is in the range 0 .. 255) and convert it to the range 0 .. 1 (including fractional numbers). (0 -> 0, 255 -> 1, 128 -> 1/2). Divide by 255.
Next step, take that new value and compute the value to the gamma power.
(expt val gamma)
.
If we take a number between 0 and 1 to any power, we always end up with a number between 0 and 1.
We can then convert the result back to a component (in the range 0 .. 255) by multiplying by 255.
Gamma correction does those three steps.
If you gamma correct with a number (exponent) less than one, you make the image brighter.
If you gamma correct with a number (exponent) greater thanb one, you make the image 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)))
vs.
(lambda (x) (max 1 (- x 1)))
; I’m not sure cut and compose are that much better here.