Functional Problem Solving (CSC 151 2015S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] - [Calendar]
Current: [Assignment] [EBoard am] [EBoard pm] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards am] [EBoards pm] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014F)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Book Office Hours] - [Issue Tracker (Course)]
Overview
Admin
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 usingimage-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
ifor as anything after a test in acond. "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 withlambdain the same way thatletinteracts withlambda.
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.
Four types of problems (I'll only ask two)
Evaluate a series of expressions
> (map (r-s / 2) (iota 10))
> (map (o (l-s + 2) (r-s / 5)) (iota 10))
Write a Boolean procedure
Write a procedure that takes three numbers as input, x, y, and epsilon, and returns true if the distance between x and y is less than epsilon and false otherwise.
(define close (lambda (x y epislon) (< (abs (- y x)) epsilon)))
Write a procedure that involves a conditional
"Write a procedure that takes a value as an input and
returns string if it's a string, real if it's a
real, and other, if it's something else."
(define type (lambda (val) (cond [(string? val) "string"] [(real? val) "real"] [else "other"])))
Answer a question I've already asked in class about conditionals or other recent topics. (E.g., similarities and differences between types of conditionals.)