Class 9: Writing Your Own Procedures, Continued
Held: Monday, 6 February 2017
We continue to consider new ways to write your own procedures and why you might do so.
Preliminaries
Overview
- Evaluation in Scheme
- More about procedures
- Lab
- Questions and reflection.
Related Pages
-
Reading: Writing Your Own Procedures
Updates
News / Etc.
- New partners!
- Quiz 1 returned.
- Note that
(irgb-lighter c1)
does not modifyc1
. Instead, it returns a new color. - That should not be surprising. You would not expect
(square x)
to changex
. - Some of you missed that since the result of
compose
is a procedure, it implicitly has a parameter. For example, we would describe the result of(define irgbll (compose irgb-lighter irgb-lighter))
as “A procedure,(irgbll color)
, that computes(irgb-lighter (irgb-lighter color))
. - That means that the solution to problem 1 should have been something
of the form
(define myfun (compose ....))
.
- Note that
- Our graders’ account got locked last night. (Even I don’t have access right now.) I’m not sure where we stand in grading.
- Exam 1 will be distributed on Wednesday.
Reminders
- I’m always happy to (try to) answer questions via email. There is no need to apologize when sending me questions. If I take too long to answer, send another email (or even text, if it’s a reasonable hour).
- We have tutors available Sunday through Thursday evening from 7-10 p.m. in Science 3813/15.
- We have mentor sessions on Wednesday and Thursday evenings from 8:00-9:00 p.m. in the CS Commons. Wednesdays will be more Q&A, Thursdays will include sample quizzes.
- I run review sessions on Thursdays at 9am in this room.
- We have individual tutors available for those who take advantage of the above and find that it’s not enough.
Upcoming Work
- Assignment 3. Due Tuesday!
- Reading: Output in Scheme.
- Reading: Simple input in Scheme.
- Lab writeup: Exercises 4, 5, and 6. Due Wednesday before class.
Extra credit (Academic/Artistic)
- CS Table, Tuesday, 7 Feb 2017. Something on privacy. See email.
- Thursday extras, Thursday, 9 Feb 2017, 4:15 p.m., Science 3821: Something on computer graphics (visitor from UMN). Let me know if you want the email.
- Scholars Convocation, Thursday, 9 Feb 2017, 11:00 a.m., JRC 101.
Extra credit (Peer)
Good things to do
Evaluation in Scheme
- Two main issues:
- Table that associates names and values.
- Where we are in the expression we are evaluating.
- General process
- Evaluate from inside out
- If you see a name, look it up in the table
- If you see a value, leave it as is
- Complication from procedures
- We also look up procedures in the table.
- When we run a procedure, we temporarily update the table, associating the values of parameters for their names.
More About Procedures
- Three mechanisms for making procedures.
- Composition: Given multiple existing one-parameter procedures, string them together to make a new procedure.
- Sectioning: Given an existing multi-parameter procedure, make a new procedure that fills in some parameters with constant values.
- General/Lambda: Parameterize a chunk of code by writing
(lambda (inputs) ...)
. - For composition and sectioning, we don’t name the parameters.
- For lambda, we name the parameters, but Scheme doesn’t really care what we name them.
Lab!
- Work on the procedures lab.
- We’ll probably try to reflect a little bit at the end.