This class will be recorded! Its use is limited to members of the class. Please do not share with others.
Approximate overview
I will post details to the Announcements channel.
You can respond to recordings for the tokens, provided you do so within one week of the event. I would, however, prefer that you attend “live”.
Your response is a reflective paragraph, sent via email.
You can also suggest events.
I’ll try to include this list of upcoming work each day. Your colleagues have created a Discord Channel that they will demo for you.
Meets expectations
(above (circle 20 'solid "black")
(beside (circle 20 'solid "black")
(circle 20 'solid "black"))
(beside (circle 20 'solid "black")
(circle 20 'solid "black")
(circle 20 'solid "black")))
Also meets expectations, even though it doesn’t work.
(above circle 20 'solid "black")
beside (circle 20 'solid "black")
(circle 20 'solid "black"))
(beside (circle 20 'solid "black")
(circle 20 'solid "black")
(circle 20 'solid "black"))))))))
Better (probably the best you can do right now)
(define ball (circle 20 'solid "black"))
(above ball
(beside ball ball)
(beside ball ball ball))
Overkill (beyond what you can do right now)
(define ball (circle 20 'solid "black"))
(define row-of-balls
(lambda (n)
(if (= n 1)
ball
(apply beside (make-list n ball)))))
(define pyramid
(lambda (rows)
(apply above (map row-of-balls (cdr (iota (+ 1 rows)))))))
Clarification: Are quizzes satisfactory / non-satisfactory?
Yes
Why do you need zero-parameter procedures?
They may depend on things in the “environment” that change.
Sometimes we want computations done delayed.
We can “protect” some of the variables within the body from the outside world, avoiding confusion (and renaming of variables).
Randomness is something that will change.
Why is above not defined?
Make sure to do the
(require 2htdp/image). Sam will check in during lab.
What do quizzes cover?
Generally, the prior day (and before).
Likely, a problem related to the prior day’s lab.
Can you reflect an image over an axis? I couldn’t find it in the big image documentation.
Sam will try to figure it out.
Or the smart students notes that
flip-horizontalandflip-verticalwork.
Can we nest procedure calls?
Yes.
Bring up readings in your browser.
(Don’t bother opening DrRacket.)
Go to the Quiz in Gradescope.
Five minutes (more or less).
The big question: How does DrRacket (or any Racket interpreter) evaluate the code you enter?
Like most programs, the DrRacket interpreter deals with both data and instructions (an algorithm).
The most important data is a “table” that maps names to values.
> (define x 10)
> (define y "Hello")
; x: 10
; y: "Hello"
Each time Racket sees a define, it updates the table.
> (define x 11)
; x: 11
; y: "Hello"
> (define y (* x x))
; y: 121
For (define NAME EXP), the evaluator evaluates the expression and
then updates the table to associate the name with the expression.
You can only define a name once in the definitions pane.
However, you can re-define a name in the interactions pane. (Not generally encouraged.) [Variables in Racket don’t vary.]
Racket evaluates expressions one at a time, in order, inside-out. (Yay sequencing!)
(display "Hello")
(display (+ 2 3))
; Does the "Hello" first
; Then adds 2 and 3
; Then displays the sum
The big question: How does it evaluate an expression? The answer: It depends on the kind of expression.
Expression type 1: A number, like 123. Treat that like the number.
Expression type 2: A string, like "Hello". Treat it verbatim (as a string).
> "Hello"
"Hello"
> "(+ 1 2)"
"(+ 1 2)"
> (string-length "(+ 1 2)")
7
Expression type 3: Symbols, like `solid. Similar to strings, but no string-length.
Expression type 4: A sequence of letters and numbers, like x or
are-you-bored-yet? Looks them up in the table. If it’s in the
table (something we’ve defined), gives the corresponding value.
Otherwise, issues an error message.
(name-of-proc params)define, as in (define NAME EXP)lambda (which means “procedure”), as in (lambda (PARAMS) BODY)Expression type 5a: Evaluate all of the params, then runs the procedure (using the mental/substitutive model from the reading)
Expression type 5b: Evaluates the expression and then updates the table.
Expression type 5c: Does nothing (other than noting that it’s a procedure); just represents a set of instructions that can be computed later.
> (define f (lambda (x) (* x (+ x x))))
; f: procedure with inputs x and body (* x (+ x x))
Expression type 5a, revisited: If the procedure is a user-defined procedure, it evaluates all of the params, then substitutes each for the corresponding input in the body, then evaluates body.
; f: procedure with inputs x and body (* x (+ x x))
> (f (+ 3 4))
; First, evaluate the (+ 3 4) = 7
; --> (f 7)
; --> (* 7 (+ 7 7))
; --> (* 7 14)
; --> 98
Summary
Q&A
What should we do if there are multiple expressions to evaluate?
Pick an order. (Left to right is always good.)
New pairs! Let’s hope Sam can get the code to run.
You will not be able to finish in class. Sorry. You may finish on your own or arrange a time to meet with you partner later.
Sam (well, Sam using a computer program he wrote) assigns groups.
First person in the group goes to the Lab Sessions channel, clicks the camera (or something equivalent) and then “Meet Now”. Please get the channel right. We won’t see you in other channels.
Add a subject. “Group # (Names)”, such as “Group 1 (SamR & JohnG)” Please get the group name right. It makes it much easier for us.
Click “Meet Now”.
Invite the other members of the group.
Other members of the group join. (Today, you can start discussions once you have two in the group. Generally, you’ll wait until everyone is there.)
Discuss/work/whatever.
There are four problems. You should submit at least the first three by the end of class. Sam will warn you when there are ten minutes left in class so that you can decide whether to submit the first three problems or try to do all four together.
We won’t have time, but I like to leave the potential there.