Functional Problem Solving (CSC 151 2015F) : EBoards

CSC151.01 2015F, Class 11: Documenting Programs and Procedures


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support

Questions

Even though I've completely blown the *two days* policy for extra credit, will you have sympathy on me because my sister burned her finger?

Yes

What do you want me to write in the extra credit thing?

A reflection on the event. A few sentences.

Who do we send the extra credit responses to?

rebelsky@grinnell.edu

Doesn't putting your email address on a Web page lead to spam?

Yes.

Can we use your irgb-average on problem 4 from yesterday's lab?

Certainly! The goal was to annotate, not to have to write from scratch.

I think my procedures are right for HW3, but I'm having trouble converting to lambda.

Sam's hypothesized example

    (define color1 (irgb 200 100 40))
    (define color2 (irgb 100 200 50))
    (define average (irgb (* 1/2 (+ (irgb-red color1) (irgb-red color2)))
                          (* 1/2 (+ (irgb-green color1) (irgb-green color2)))
                          (* 1/2 (+ (irgb-blue color1) (irgb-blue color2))))

General model

    (define input1 ...)
    (define input2 ...)
    (define computedvalue EXPRESSION) 

    (define compute-value
      (lambda (input1 input2)
        EXPRESSION))

Back to example (define my-irgb-average (lambda (color1 color2) (irgb (* 1/2 (+ (irgb-red color1) (irgb-red color2))) (* 1/2 (+ (irgb-green color1) (irgb-green color2))) (* 1/2 (+ (irgb-blue color1) (irgb-blue color2))))))

What's the relationship between this color1 and color2 and the ones we defined earlier?

There is none. Scheme will just use those names for whatever you provide as input to your procedure.

Should we have parameters that have the same names as variables (or vv)?

It works, but it's probably not a good idea because it will confuse someone (maybe you, maybe me, maybe the grader)

You should choose good names for your parameters and variables, even though it is possible to pick really bad ones. Think of how hard it is to read

(define irgb-munge
  (lambda (- whatever)
    (irgb (+ whatever (irgb-red -))
          (+ whatever (irgb-green -))
          (irgb-blue -))))

Can I use a procedure as an input to another procedure with lambda?

Yes! As long as you use the parameter in the place we expect a procedure to be.

    (define apply-to-blue
      (lambda (transformation)
        (transformation (irgb 0 0 255))))

Can we define using lambda?

Not right now.

Pair programming

You have a classmate (or mentor) (or teacher) who has not read the article. Your goal is to summarize the central points.

Documentation

You have a classmate who has not read the reading. Your goal is to summarize the central points.

Documentation Practice

(max v1 v2)

    ;;; Procedure:
    ;;;   max
    ;;; Parameters:
    ;;;   v1, a real number
    ;;;   v2, a real number
    ;;; Purpose:
    ;;;   Takes the maximum value of v1 and v2, whichever is larger
    ;;; Produces:
    ;;;    result, a number, the larger of v1 and v2
    ;;; Preconditions:
    ;;; Postconditions:

    ;;; Process:

To be continued ...

(max v1 ... vn)

(irgb-average c1 c2)