Approximate overview
Events
Do all of our procedures for part three of MP1 have to create images?
Yes.
What counts as innovative?
Innovation is in the eye of the beholder. Or the grader. Something like that.
How do we meet with you on Teams?
Wait until your appointment.
I should DM (Chat) you a message like, “Are you ready to meet?”
Respond.
I will then click the magic camera button to connect.
Note: Sometimes meetings run over. If I am not available, just DM me and say “Aren’t we meeting?” or something like that.
What if we don’t have an appointment?
DM (Chat) me to see if I’m available or to ask a question.
What are those #| ... |# sections in the labs?
Those are comments, parts that can be read by human beings, but that DrRacket ignores. We use those for English text or code we don’t want executed.
What are those semicolons?
Those are one-line comments. DrRacket ignores everything between the semicolon and the end of the line.
You can use either.
Can we get rid of those ugly “TODO” sections when we fill in our answers?
Yes.
How do we write grid?
;;; (grid img) : image?
;;; img : image?
;;; Create a grid of four copies of img, arranged in
;;; two rows of two copies each.
(define grid
(lambda (img)
(above (beside img img)
(beside img img))))
How does grid help me make a checkerboard?
You can think of it as decomposing the big checkerboard into smaller things or of building up the smaller things into the big checkerboard.
We have some procedures and values that have been provided for us.
;;; (color-square side-length color) -> image?
;;; side-length : non-negative-integer?
;;; color : color?
;;; Create a solid square in the given color.
(define color-square
(lambda (side-length color)
(rectangle side-length side-length 'solid color)))
;;; red-square : image?
;;; A small red square, useful for exercises in this lab.
(define red-square (color-square 20 'red))
;;; black-square : image?
;;; A small black square, useful for exercises in this lab.
(define black-square (color-square 20 'black))
;;; two-by-two : image?
;;; A two-by-two grid of alternating red and black squares.
(define two-by-two
(above
(beside red-square black-square)
(beside black-square red-square)))
Working from the bottom up, we can make a grid of two-by-twos, which will give us a four-by-four checkerboard.
;;; four-by-four : image?
;;; A four-by-four grid of alternating red and black squares
(define four-by-four
(grid two-by-two))
And we can then make a grid of those to make an eight-by-eight checkerboard
;;; checkerboard : image?
;;; An eight-by-eight grid of alternating red and black squares
(define checkerboard
(grid four-by-four))
Of course, given that we can replace each value by its definition, we would write a simpler definition of checkerboards.
(define checkerboard2
(grid (grid two-by-two)))
Note that we gain a lot of power from a simple procedure.
What might you have learned from the WowButter and Blackberry Preserve Exercise?
A new form today: Lots of problems with A as driver, then lots of problems with B as driver. Sometime in the near future, we’ll discuss which form you like better.
Make sure that you use the file basic-types.rkt.
Important! We will continue this lab on Wednesday! (Same partners.)
Why is (sqrt 2) rational? I was taught that it’s an irrational
number.
The square root of 2 is irrational. However, when you ask DrRacket to compute the square root of 2, it approximates it as 1.4142135623730951. Any finite number is rational. This one could be expressed as, say 14142135623730951/10000000000000000 (I may have gottten the wrong number of zeroes).
Why do I get -4.440892098500626e-16 for 2 minus the square of the square root of two?
That’s scientific notation for -4.44… * 10^(-16). It’s close to zero, but not exactly zero.
Why is (remainder -8 8) zero?
-8 = -1*8 + 0
Why is (remainder -7 8) negative seven rather, than, say, one?
-7 = 0*8 + -7
-7 = -1*8 + 1
For the DrRacket
remainder, we make sure that the remainder has the same sign as the dividend.
What is (round 5/2)?
2
What is (round 3/2)?
2
Why?
If you are doing accounting (or statistics) and always round 1/2 the same direction, you will bias your results. By rounding toward “even”, you get less bias.
Warning! Racket can represent some very large integers. But it also takes a very long time to print them out.
(define large (expt 3 12314125))
Five minutes later, and it’s still printing out digits.
Save early, save often. Ignore Sam’s strange jokes.