Functional Problem Solving (CSC 151 2015S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] - [Calendar]
Current: [Assignment] [EBoard am] [EBoard pm] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards am] [EBoards pm] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014F)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Book Office Hours] - [Issue Tracker (Course)]
Overview
Admin
What's an argument?
Another name for parameter.
Some people use "parameter" for "thing in procedure declaration" and "argument" for "thing in procedure call".
We are not that careful.
How do I type complex numbers?
Number plus/minus number letter i, as in the following. No spaces allowed!
> 3+4i
3+4i
> (* 3+4i 3+4i)
-7+24i
> 3-4i
3-4i
Here's what happens if you have spaces
> 3 + 4i
3
#<procedure:+>
4i: undefined;
cannot reference an identifier before its definition
For the quiz, do we have to understand that weirdo representation of
drawings, like (drawing ellipse 123123 "" 10 20 30 40).
No.
In case you care, it's the symbol 'drawing, the symbol 'ellipse, a strange numeric representation of the color, something pointless, the left boundary, the top boundary, the width, and the height.
Can you explain why we get the result we do for (modulo -9 8)?
We try to think of the result of
(modulo x y)as thebinx = a*y + b.-9 = -1*8 + -1
-9 = -2*8 + 7
We use the first approach when computing remainder.
(Rule: The remainder has the same sign as the dividend.)We use the second approach when computing modulo. (Rule: The modulo value has the same sign as the divisor.)
The circle model also shows this. (Ha ha. If you didn't come to class, you can't see it.)
Why are scaling and shifting not interchangable?
If you think about scaling a compound drawing, you want the relative positions of the parts to scale, rather than to have each part scale around its center. (Another case in which the whiteboard shows more info than the eboard.)
Can you write a procedure for something that makes a figure-eight-like shape? (Two circles stacked on top of each other)
Design questions.
Tell me more about the shape - Are the two circles the same size, or is the top one slightly smaller or ....?
What inputs will I want?Answers: Two identical size circles. Name it "eight". Inputs will be radius, color, location (of center)
Strategy: Multiple steps. First we'll make a small figure eight at the origin. We do that by shifting one copy of the unit circle up half its height and one copy of the unit circle down half its height.
(drawing-group (vshift-drawing -0.5 drawing-unit-circle)
(vshift-drawing 0.5 drawing-unit-circle))
Next step: Scale it. (We generally like to scale before shifting, but sometimes small shifts, like those above, are good.)
(scale-drawing (* 2 radius) ...)
Shift it over
(hshift-drawing
center-col
(vshift-drawing
center-row
...))
Put in the "it's a procedure" information
Putting it all together
(define figure-eight
(lambda (radius center-col center-row)
(hshift-drawing
center-col
(vshift-drawing
center-row
(scale-drawing
(* 2 radius)
(drawing-group (vshift-drawing -0.5 drawing-unit-circle)
(vshift-drawing 0.5 drawing-unit-circle)))))))
Important lesson: Break it up into smaller parts.
Lesson two: Sometimes you want to shift before scaling. (And then shift again.)
Lesson three: Work around the origin as a starting point.
How would you design this differently if you were to have the top and bottom circles different sizes?
I might use the "inflection point" (probably needs a better name), rather than the center. (But maybe left and top.)
I'd take two radii instead of one.
I'd expect more work.
On the homework, please explain what you want for center-peg.
See the following example
(define peg-one (circle 50 20 30 "red"))
; red circle, radius 50, eetc.
; the circle procedure comes from exercise 4 on the procs lab
(define hole-one (circle 100 90 80 "green"))
; green circle, radius 100, etc.
(define combo (center-peg peg-one hole-one))
; red circle, of radius 50, centered at (90,80), put on top
; of a green circle of radius 100, also centered at (90,80)
You should be able to achieve this with shifting and grouping.
Consider the following sequence of definitions
(define d1 (hshift-drawing 50 drawing-unit-circle))
(define d2 (hshift-drawing 20 drawing-unit-square))
(define d3 (scale-drawing 5 (drawing-group d1 d2)))
(recolor-drawing d2 "red")
(define d4 (scale-drawing 20 d1))
(image-show (drawing->image (drawing-group d3 d4) 100 50))
Sketch the result
The "simple geometric center" of a drawing is the point horizontally
midway between the left edge and the right edge of the drawing, and
vertically midway between the top edge and the bottom edge of the
drawing. Recall that there is no drawing-bottom or drawing-right
procedure. Sketch the code you would use to find the x coordinate of
the center of drawing my-drawing. (You don't know the definition of
that drawing.)
(define center-x
(+ (/ (drawing-width my-drawing) 2)
(drawing-left my-drawing)))