Functional Problem Solving (CSC 151 2015F) : EBoards

CSC151 2015F, Review Session 04 - 2015-09-24


Overview

Administrative Q&A

Really important question that you had to be here to hear.

Really important answer that can never be repeated.

Will you put our grades on PWeb?

No.

How will we know how we are doing?

I will send you email once in a while. Probably late next week.

You should know how you are doing from the quizzes you receive.

How will we know if we are failing?

APRs. (Academic Progress Reports.) Midsem grade reports for first-year students.

Questions and Answers

Do I need an intuitive understanding of modulo? How does it relate to remainder?

Modulo is useful when we want positive cycles

    > (map (section remainder <> 4) nums)
    '(-1 0 -3 -2 -1 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2)
    > (map (section modulo <> 4) nums)
    '(3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2)

How were we supposed to do the stupid image-variant question on the exam?

We'll assume that you've written irgb-bound-components.

What form does image-variant take? (image-variant image color-proc)

For this problem, what do we need the procedure to do? Bound the components between 64 and 128.

    (define bound-64-128
      (lambda (color)
        (irgb-bound-components color 64 128)))
    (define image-mid
      (lambda (image)
        (image-variant image bound-64-128)))
    (define image-mid
      (lambda (image)
        (image-variant image (section irgb-bound-components <> 64 128))))

The purpose in the six P's can be hard to do when it's combined with code reading. Can we look at the exam question?

    (define fun
      (lambda (n i)
        (quotient (remainder n (expt 10 (+ i 1))) (expt 10 i))))

As we play with this, we might observe a pattern. Or we could try doing the parts by ourselves.

Sample Quiz Questions

Three kinds of questions (you'll probably only get two)

(and (or 2 4) (or #f 5))

Rule: "or returns the first non-false parameter (or false, if all parameters are false)

Rule: and returns #f if any of the parameter are false, the last parameter if all of the parameters are non-false

How Scheme evaluates?

    1. We have an and!  Look at the parameters one by one.

    2. The first parameter is `(or 2 4)`  We need to evaluate that

    2a. We have an `or`!  Look at the parameters one by one.

    2b. The first parameter is 2.  2 is not false.  We return 2.

    3. We've evaluated the first parameter to `and`.  It's not false.
    Go on to the next one.

    4. The next parameter is `(or #f 5)`.  It's an expression.  We
    need to evaluate it.

    4a. We  have an `or`!  Look at the parameters one by one.

    4b. The first parameter is `#f`.  That's false.  We need to look
    at the next one.

    4c. The next parameter is 5.  That's not false.  We return 5.

    5. We've run out of things in the `and`.  We return the last
    value.  It's 5.

Don't forget the value of (and) and (or)

Can you write a sample test procedure?

Expect