CSC 151.01, Class 05: Writing your own procedures
The normal “start of class algorithm”
- Take any handouts. (There will not always be handouts.)
- Grab a card.
- Read the name of the workstation and its location.
- Attempt to determine where that workstation is.
- If you have difficulty, ask the instructor or mentor.
- Put the card in the jar.
- Make your way to the indicated workstation
- Have a seat
- If you are the second person there, introduce yourself.
Overview
- Preliminaries
- Notes and news
- Upcoming work
- About assignment 5
- Extra credit
- Questions
- Lab
Preliminaries
News / Etc.
- Thanks for keeping the room neat.
- In contrast, the experiment in entropy that is my office appears to
have consumed your first quiz. I have brought you fruit snax as
a replacement.
- I do realize that there’s no relationship between the two.
- Amazingly, I found the quizzes eight minutes before the start of class. You’ll get them back Friday.
Upcoming work
- Quiz Friday!
- Topics: Numbers (and operations), Strings (and operations), Lists (and operations), The composition operator
- The quiz will not ask you to write procedures, except with the composition operator.
- Review sessions Thursday night at 7pm and 8pm in 3821.
- Our mentors will also distribute a sample quiz and answers.
- Assignment 3 due next Tuesday.
- Today’s partner is your partner for assignment 3.
- Flash cards due at 5pm TODAY.
- Submit ten flash card Q&As via email
- Mail to rebelsky@grinnell.edu.
- Use a subject of “CSC 151.01 Flashcards (Week 2)”.
- Readings (online), due before class Friday.
- Lab writeup for class 5, due before class Friday.
- Exercise 1b or 2.
- “CSC 151.01 Writeup for Class 5 (Your Name)”
- Mail to csc151-01-grader@grinnell.edu
Typical quiz questions
This quiz normally involves questions in which you interpret or write simple expressions.
- What result will you get from this expression?
(map (o increment increment) (iota 5)) - Consider the following definitions, what results will you get?
(define quad (o square square))(quad 2)(quad 4)(quad "five")(quad (quad 2))
- Write an expression to generate the list
(-2 -1 0 1 2)usingiota,map, and a procedure of your choice.
About assignment 3
- We’ll walk through it together and give you a chance to ask questions.
- Time for questions on Friday (and Monday)
Extra credit (Academic/Artistic)
- Rebecca Wingo: How to Harvest History. Friday Feb. 2, 4pm, Burling
Library Lounge.
- Workshop: Saturday Feb. 3, 10-1, DLab
- Register for workshop at https://grinnell.formstack.com/forms/wingo_workshop
- CS Extra, 4:15 p.m. Thursday, Science 3821: Expanding the pipelines
through innovative code camps
- Drinks and snacks at 4:00 p.m. in the CS Commons
Extra credit (Peer)
- Posse Plus Retreat Recap, February 6 at 11am, JRC 101.
Extra credit (Misc)
Other good things
Questions
- Can you tell me more about the Rebecca Wingo visit?
- The History Harvest is a community-based, student-driven archive project. Over the course of a semester, History Harvest students partner with a community group to run an event in which members of the community bring artifacts of significance, artifacts that tell their story. Students record community members as they tell stories about their objects and digitize the artifacts for an online archive. The community members then take their items back home. This one-day event is a bit like Antiques Roadshow, except everything is valuable. Back in the classroom, students edit the audio, establish metadata for the items, and upload the items to Omeka, an archival content management system. This workshop will walk you through a mini-Harvest and teach participants the skills they need to run their own History Harvest.
- It’s Monday evening. My partner did not show up for our meeting. What should I do?
- Do the homework on your own.
- Hope that this doesn’t happen again. (If it does, my inclination will be to attribute the problem to you, rather than your partner.)
- I’m having trouble getting the syntax of Scheme right. It makes me feel less than competent.
- You’re learning a new language. It takes time to master.
- After a week of Russian, you would expect to be making mistakes.
- The computer is just less nice about them than, say, the language assistant.
- Some members of this class seem to have more background than I do.
- Yup. Some people took CS classes in high school or explored on their own.
- But we’ve tried to design the class for people with no background.
- By midway through the semester, it is unlikely to make much difference.
- Right now, they are probably more confident on things like syntax and “thinking like a computer”.
- What is the difference between the map and the map1 procedure? Sometimes it seems to matter which one you use, and other times they are interchangeable.
- Ignore
map1. Just usemap. We had addedmap1as an experiment last semester and forgot to remove it this semester. (I think we’ve now erased the traces ofmap1. - Can we go over the solution to problem 5 in the simple lists lab a bit more thoroughly?
- Certainly. It reveals an important point.
#lang racket
(require csc151)
(define large-illness-ratings
(list 7 4 0.2 -3 6 5.5 5 6 -1.5 54/7 0))
; * Recall expression (min (max val lower) upper)
; * This expression takes any numeric value and, if it's less than lower,
; returns lower. If it's greater than upper, returns upper. Otherwise,
; returns the original value.
; * How does it work?
; * Scheme evaluates from the inside out.
; * (max val lower) returns
; * The larger of val and lower
; * If val is less than lower, (max val lower) returns lower
; * If val is greater than or equal to lower, (max val lower)
; returns val.
; * The next computation is (min SOMETHING upper)
; * This returns the smaller of SOMETHING and upper
; * if SOMETHING is smaller than upper, it returns SOMETHING
; * If SOMETHING is larger than upper, it return upper
; * Putting things together, we've achieved our goal
(define bound-rating
(lambda (rating)
(min (max rating 0) 6)))
#|
> (bound-rating 5)
5
> (bound-rating 50)
6
> (bound-rating -50)
0
> (map bound-rating large-illness-ratings)
'(6 4 0.2 0 6 5.5 5 6 0.0 6 0)
|#
; But that relies on new material. What I really want to
; do is convert the original (min (max val lower) upper)
; to lists.
; Normal strategy: Throw in `map` and rework as necessary.
#|
First attempt
(map min
(map max
large-illness-ratings
0)
6)
. . map: contract violation
expected: list?
given: 0
argument position: 3rd
other arguments...:
|#
#|
Observartion: I needed lists
Second attempt
(map min
(map max
large-illness-ratings
(list 0))
(list 6))
map: all lists must have same size; arguments were: #<procedure:max> '(7 4 0.2 -3 6 5.5 5 6 -1.5 54/7 0) '(0)
|#
#| Third attempt
(map min
(map max
large-illness-ratings
(make-list (length large-illness-ratings) 0))
(make-list (large-illness-ratings) 6))
. . application: not a procedure;
expected a procedure that can be applied to arguments
given: '(7 4 0.2 -3 6 5.5 5 6 -1.5 54/7 0)
arguments...: [none]
|#
#|Final(?) attempt
(map min
(map max
large-illness-ratings
(make-list (length large-illness-ratings) 0))
(make-list (length large-illness-ratings) 6))
'(6 4 0.2 0 6 5.5 5 6 0.0 6 0)
|#
- Can we go over the last problem in the simple lists lab?
- Another day
Lab
Writeup: Exercise 2
Hints: You’ll probably need to use the composition and section operators.
Note: If you don’t understand them, ask!