Functional Problem Solving (CSC 151 2015S) : EBoards

CSC151.01 2015S, Review Session 6: Conditionals and Beyond


Overview

Admin

Your Questions

Can you explain image-compute a bit more?

It iterates through all the column/row pairs, calls the function on the column/row pair, gets the color, and then calls image-set-pixel! at the location. (Although it does this a bit more efficiently than using image-set-pixel!.)

How do we get different colors at different pixels?

Since we're providing different (col,row) pairs, the function can compute different values.

Are we guaranteed to different values at different pixel?

No. It depends on the function. The following is just black.

    (image-compute
     (lambda (col row) (irgb 0 0 0))
     100 100)

Can we make different things happen on two halves of the image?

Yes. We will just need to use conditionals.

    (image-compute
     (lambda (col row)
       (if (> col 50)
           (irgb 0 (* row 2.55) 0)
           (irgb 0 0 (- 255 (* row 2.55)))))
       100 100)

Do we need to know when, if, and cond for the quiz?

Yes.

What's the relationship between "expression" and "consequent"?

A consequent is one kind of expression. We use the term "consequent" when the expression appears as the first thing after the test in an if or as anything after a test in a cond. "Consequent" means "something that follows as a result or effect" [Google 2015], and the consequent is something we evaluate as a result of the test holding.

What are the relationships between lambda and let?

Two basic ones

    (let ([...])
      (lambda (...) ...))

    (lambda (...)
      (let ([...])
        ...))

In the first, we evaluate the bindings in the let once, when we click "run" (or otherwise evaluate the expression). In the second, we evaluate the bindings every time we call the function.

In the second, the bindings can depend on the parameters. In the first, they cannot.

In practice, we sometimes do both

    (let ([...])
      (lambda (...)
        (let ([...])
          ...)))

    (lambda (...)
      (let ([...])
        (lambda (...)
          ...)))

let* interacts with lambda in the same way that let interacts with lambda.

What should we know about anonymous procedures?

(At least) four ways of making them.

With lambda expressions. (lambda (x) (increment (square x))), (lambda (x) (+ 2 x)).

Using composition. (o increment square). Note that this is shorter, it doesn't introduce a variable that we have to remember. And it is eventually as easy to read.

Using sectioning. (l-s + 2) is also more concise and eventually easier to read. ("I'm filling in the left parameter of + with 2")

The homework has a problem in which we need to vary two parameters. Can we use sectioning?

Not the sectioning you've learned. In that case, you need a lambda.

What Will the Quiz Look Like?

Four types of problems (I'll only ask two)