Functional Problem Solving (CSC 151 2016S) : EBoards

CSC151.02 2016S, Review Session 4 (2016-02-18)


Thank you to the students who showed up so that we get a review session that other students can read over later.

Notes

Overview

Current Topics

Questions

Will you use the pictures from the pictorial list?

No

Do we have to know last names?

No

Will they be alphabetical by last name?

No

Will they be alphabetical by last first name?

No

Some Stuff on Six P's

I don't get postconditions

An attempt to formalize what the result of the procedure.

We work with informal description under "Purpose".

    ;;; Procedure:
    ;;;   enlarge-drawing
    ;;; Parameters:
    ;;;   n, an integer
    ;;;   drawing, a drawing
    ;;; Purpose: 
    ;;;   Makes the drawing n percent bigger
    ;;; Produces:
    ;;;   bigger, a drawing
    ;;; Preconditions:
    ;;;   ...
    ;;; Postconditions:
    ;;;   The width is 1+percent/100 of the original width, that is.
    ;;;     (drawing-width bigger) = (* (1 + percent/100) (drawing-width drawing))
    ;;;   (drawing-height bigger) = (* (1 + percent/100) (drawing-width drawing))
    ;;;   The left and top are the same.  That is ...
    ;;;      (drawing-left bigger) = (drawing-left drawing)
    ;;;   (drawing-top bigger) = ...

What should we generally say for process

Most of the time, when we are using procedures, we only care about what they accomplish and not how they accomplish it.

Process explains the "how" of a procedure. How does it accomplish its goal. (High-level.)

Process is an optional "P", like "Philosophy" and "Props" (not completely optional) and "Practica" and "Problems"

Can we talk more about drawings?

Drawings are a way of thinking about images that we might make.

We can think about building images with just circles and squares (and ways to transform those circles)

Conceptually, we have a bunch of circles and squares.

The bunch of circles and squares describes the image. We can then tell the computer to draw that image with drawing->image or something similar.

What kinds of things can you do with the circles and squares? Make them bigger (scale), move them (shift), color (recolor), group (group, compose)

An ellipse of width 20 and height 10, centered at (40,30)

    (vshift-drawing 
     30
     (hshift-drawing 
      40
      (vscale-drawing
       10
       (hscale-drawing 
        20
        drawing-unit-circle))))

If you prefer a more Germanic approach, we also have

    (drawing-vshift
     (drawing-hshift
      (drawing-vscale
       (drawing-hscale
        drawing-unit-circle
        20)
       10)
      40)
     30)

Should we scale before shifting? (That is, should it be innermost?)

We usually do so, because scaling changes the position. So we usually scale and then move to the position.

For example

    > (define sam (hshift-drawing 10 (vshift-drawing 20 drawing-unit-circle)))
    > sam
    '(drawing ellipse 0 "" 9.5 19.5 1 1)
    > (hscale-drawing 10 sam)
    '(drawing ellipse 0 "" 95.0 19.5 10 1)

    > (define sam (hshift-drawing 10 (vshift-drawing 20 (scale-drawing 10 drawing-unit-circle))))
    > (image-show (drawing->image sam 100 100))
    4
    > (image-show (drawing->image (scale-drawing 5 sam) 100 100))
    5

We can think of drawings as having multiple components

Unlike colors, which combine them into a single number, drawings give them to us in almost-readable fashion.

What happens when we try render a drawing outside the bounds of the canvas?