Functional Problem Solving (CSC 151 2015F) : EBoards

CSC151.01 2015F, Class 19: Anonymous Procedures, Revisited


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support

Quiz 4

Discuss with your partner, then be prepared to answer in class. You will need to look at the eboard for all of the questions. You may experiment with code after discussing with your partner.

  1. What is the output of the following?

    > (define x 5)
    > (square x)
    25
    > x
    5
    
  2. What is the output of the following?

    > (define color (irgb 200 0 100))
    > (irgb->string (irgb-redder color))
    "232/0/100" 
    > (irgb->string color)
    "200/0/100"
    
  3. What is the output of the following?

    > (define d19 (scale-drawing 10 drawing-unit-square))
    > (drawing-width (scale-drawing 2 d19))
    20
    > (drawing-width d19)
    10
    
  4. After the following commands, what are the color, left, top, width, and height of d1 and d2?

    (define d0 (recolor-drawing "yellow" drawing-unit-square))
    (define d1 (scale-drawing 20 d0))
    (define d2 (hshift-drawing 30 d1))
    (recolor-drawing "red" d1)
    (recolor-drawing "blue" d2)
    ; d1 left is -10
    ; d2 left is 20
    ; d1 is yellow
    ; d2 is yellow
    
    
    ; We try to include a ! when we have procedures that change
    ; their input or the world around them (but not always)
    ; (image-draw-line!
    ; (image-transform!
    
  5. What is the output of the following expression?

    > (even? 0)
    #t
    
  6. What is the output of the following expression?

    > (even? 2.4)
    error
    
  7. What is the output of the following expression?

    > (< 3 5)
    #t
    
  8. What is the output of the following expression?

    > (+ 3 'two)
    error
    
  9. What does (or exp1 exp2) do?

    ; Look for the first non-false value and return that.
    ; If none of them are non-false, it gives us #f
    
  10. What is the output of the following expression?

    > (or (< 3 5) (+ 3 'two))
    #t
    
    
    ; > (or 5 (+ 3 'two))
    ; 5
    

HW4 Questions

Why doesn't my circle of drawings work?

You've correctly used sin and cos. But each gives you numbers between -1 and 1. Shifts that small tend to be invisible. Try multiplying by a larger number (say 50 or 100).

What radius should we use for the circle of drawing?

Whatever you'd like, provided it's easily visible.

Why is my neighbor one pixel off?

It probably has a left margin that is not a whole number. Unfortunately, GIMP rounds to the nearest whole number. Don't worry about it.

Do you have any general suggestions?

Write lots of helper procedures. Two that I've found useful include shift-drawing-to-origin and horizontally-center-drawing-at.

Should we use gimp tools for problem 4?

No! Use recolor-drawing when you want a different color.

Should we cite?

Yes.

Should we document add-bottom-neighbor?

Yes.

What should the postconditions for the add-aaa-neighbor procedure look like?

Something like the following

    ;;; Postconditions:
    ;;;   result contains two copies of drawing, the original and
    ;;;     a second one that is scaled by ... and placed at ...
    ;;;   (drawing-width result) =  ...
    ;;;   (drawing-height result) = ...
    ;;;   (drawing-left result) = ...
    ;;;   (drawing-top result) = ...

Should we document xcoord and ycoord?

No.

Should we handle the case in which the shadow is outside of the canvas?

No. But you also don't need to check for it.

Do we need extensive tests?

You don't need any tests. But you should be confident in your code.

Do we have to document part 4?

No.

Homework Help

Ideas from the Reading

If you have time, discuss with your partner.

What do l-s and r-s do?

What does the following do? Why would we write it?

(map 
 (lambda (i)
    (hshift-drawing (* 10 i)
                    (vshift-drawing (square i)
                                    (scale-drawing i
                                                   drawing-unit-circle))))
 (iota 20))