Approximate overview
snowman-revisited is the right height.
(Or other procedures.)top-hat procedure in the lab, but we understand
that it will take a little time to get used to it.
fancy-house should probably call painted-house and
door procedures, especially since you’d already written
painted-house.snowman-with-hat should probably call …There are other ways to think about reusing your prior code. Could
you define (snowperson-revisited height) in terms of (snowperson size)?
;;; (snowball size) -> image?
;;; size : positive-real?
;;; Make a snowball of the given size.
(define snowball
(lambda (size)
(overlay (circle size 'outline 'black)
(circle size 'solid 'grey))))
;;; (snowperson size) -> image?
;;; size : positive-real?
;;; Make a snowperson whose base is size.
;;; Height is 260/60 or 26/6 or 13/3 * size
(define snowperson
(lambda (size)
(above (snowball (* 1/2 size))
(snowball (* 2/3 size))
(snowball size))))
If size is 60, we get snowballs of radii 30, 40, and 60
(diameters 60, 80, and 120). The total height would then be 260. So we
could define snowperson-revisited as
(define snowperson-revisited
(lambda (height)
(snowperson (* 13/3 height))))
Important issue: Exact numbers are stored precisely; inexact numbers can be approximated. For integers, you’ll see problems when you get to large numbers. For smaller numbers with a fractional part, you’ll see a variety of issues.
Exact integers are stored exactly. Inexact integers are approximated. For large enough values, you’ll see a difference.
> (- (+ 1 (expt 10 50)) (expt 10 50))
> (- (+ 1 (expt 10.0 50)) (expt 10.0 50))
We generally prefer exact numbers. However, inexact numbers naturally crop up in our calculations. There are also some storage and speed advantages to using inexact numbers.
We’re beginning to see the difference between the conceptual (semantics) and how we express concepts (syntax). Consider, for example, a string that contains two quotation marks.
Strings must begin and end with quotation marks. That is, the take
the form “…”. How do we signify a quotation mark within the string?
If we just write a quotation mark, it’s indistinguishable from the
quotation mark that ends the string. Hence, we must precede it with
a backslash. "\"\"".
Behind the scenes, computers essentially store everything as numbers. The collating sequence tells you what number corresponds to each letter (or vice versa). It’s helpful to see that, say, the uppercase letters precede the corresponding lowercase letters by exactly 32, or that the digit characters appear in order. We’ll use them for those kinds of reasons.
Take a concrete implementation in Racket and create a new function that generalizes the behavior.
As you may recall in building snowmen, we found it useful to be able to create hats for the snowmen. A hat consists of three parts: a box, a brim, and a ribbon. The brim is at the bottom. The ribbon appears to be on the box, directly above the brim, although we will create it by stacking a rectangle over the box.
We’ve decided on a 50x50 grey hat with a purple ribbon. We’ve decided that brims will always be 5 units high and that ribbons will take 1/5 the height of the box. Rather than doing the calculations by hand, we’ll make Racket do the computations.
(above (rectangle (* 50 1/2) (* (- 50 5) 4/5) "solid" "grey")
(rectangle (* 50 1/2) (* (- 50 5) 1/5) 192 "purple")
(rectangle 50 5 "solid" "grey"))
Write a procedure, colorful-hat, that generalizes this approach
by taking the width, height, hat color, and ribbon color as parameters
and producing an appropriate image as output.
I’ve started putting answers to the reading questions in the readings. These are ones that didn’t naturally fit in a reading
Why do we sometimes use a symbol and sometimes use a string when defining something like a square? For instance, both (square 40 ‘solid ‘blue) and (square 40 “solid” “blue”)` are valid and produce the same image.
The designers of the
2htdp/imagelibrary decided it was nicer to support either symbols or strings. I assume they are using symbols as the primary mode, though.
How do I do Ctrl-uparrow on a Mac?
Esc-P (“previous”). You can also use Esc-N if you’ve gone back too far. We normally hit the escape and the letter in sequence.
Ctrl-Command-Uparrow also appears to work.
Make sure to update the csc151 library. (It’s always good to check.)
Make sure to introduce yourself to your partner.
Problems are labeled A and B.
The partner closer to the front of the room is Partner A. The partner further from the front of the room is Partner B. Partner A should be at the keyboard for A problems. Partner B should be at the keyboard for B problems.
Make sure to grab the basic-types.rkt file and put it into DrRacket.
All the instructions are in the file.
Today is an as far as you got is far enough day. When it’s time to submit, write
; THIS IS AS FAR AS WE GOT! SAM SAID WE COULD STOP HERE.
And then submit. You should read through the rest of the lab, though.