Functional Problem Solving (CSC 151 2016S) : EBoards

CSC151.02 2016S, Class 09: Writing Your Own Procedures, Continued


Overview

Preliminaries

Admin

Reminders

Upcoming Work:

Extra Credit

Academic

Peer

Regular Peer

No Extra Credit, But Still Good

Quiz

(define fave (irgb 250 0 42))
(define fave2 (irgb-lighter (irgb-darker fave)))
(irgb-complement fave)

The last problem: Write a procedure that adds 32 to each component.

Three possible strategies:

We need to use compose.

(define irgb-much-lighter (compose irgb-lighter irgb-lighter)) ; not allowed
(define irgb-much-lighter (compose irgb-redder irgb-greener irgb-bluer))
(define irgb-much-lighter (compose irgb-complement irgb-darker irgb-darker irgb-complement))

Similar questions were in the mentor sessions and in the notes. (And no, we did not intend to give a particular advantage to those folks.)

Questions

Can we write define in the middle of a procedure?

No.

Did you even look at what you wrote for problem 4?

I thought so. I'll fix it during class.

How much info should we provide when citing other groups?

Approximately: "I talked to Tulah's Two Taylors about problem 4 and they provided me with advice on it."

How should we cite code from the assignment?

I don't require you to cite code from assignments.

If you choose to cite such code, use something like "Taken from assignment 3 at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC151/2016S/assignments/assignment.03.html."

Or

    Curtsinger, C., Davis, J., Rebelsky, S. A., and Weinman, J. (2016).
    _Assignment 3: Color Transformations and Image Filters._  Grinnell
    College, Dept. of CS.  Online document at
    <http://www.cs.grinnell.edu/~rebelsky/Courses/CSC151/2016S/assignments/assignment.03.html>, last modified 2016-02-01; visited yesterday.

How can we wrap around given that the remainder function doesn't take decimals?

Option 1: Round to the nearest integer.

Option 2: Use a more clever calculation.

More about procedures

(define square (lambda (num) (* num num)))

(define square (lambda (renn) (* renn renn)))

(define square (lambda (color) (* color color)))

Scheme doesn't care what you call your parameters! So choose a name that makes sense to your human reader.

Be careful about what you name your parameters, as they can override existing names.

(define square
  (lambda (*)
    (* * *)))

(define square
  (lambda (+)
    (* + +)))

Ugh.

Lab, continued

Writeup: 3 ab and 5

Questions and reflection