Functional Problem Solving (CSC 151 2015F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] [Remote Access]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2015F)] [Davis (2013F)] [Rebelsky (2015S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Overview
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.
Do I need an intuitive understanding of modulo? How does it relate to remainder?
Useful for making cycles.
(define remainder-3
(lambda (val)
(remainder val 3)))
> (map remainder-3 (iota 20))
'(0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1)
> (map (section remainder <> 4) (iota 20))
'(0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3)
> (map (section - <> 5) (iota 20))
'(-5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14)
> (define nums (map (section - <> 5) (iota 20)))
> nums
'(-5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14)
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-varianttake?(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.
Three kinds of questions (you'll probably only get two)
drawing-left and
drawing-width are available to you.(and (or 2 4) (or #f 5))
Rule: "
orreturns the first non-false parameter (or false, if all parameters are false)Rule:
andreturns #f if any of the parameter are false, the last parameter if all of the parameters are non-falseHow 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?
(center drawing x y) that is
supposed to center a drawing at the point (x,y). Give input drawings
that you would use in your tests.Expect