CSC 151.01, Class 11: Boolean values, predicate procedures, and list filters
Overview
- Preliminaries
- Notes and news
- Upcoming work
- Extra credit
- Questions
- Notes from quiz 3
- Lab
- Debrief
News / Etc.
- New partners.
- Please switch driver and navigator after every problem.
- Please make sure to return your computer cards to the jar.
- Thank you for all of the excellent exam questions. You will find many Q&A in the exam.
- I did not have time to finish grading your quizzes this weekend. We will still go over them to help you understand what I expect for documentation and tests.
Upcoming Work
- Writeup for class 10 due TONIGHT at 10:30 p.m.
- Exercise 6
- To: csc151-01-grader@grinnell.edu
- Subject: CSC 151.01 Writeup 10 (YOUR NAMES)
- Writeup for class 11 due Wednesday at 10:30 p.m.
- Exercise 4c
- To: csc151-01-grader@grinnell.edu
- Subject: CSC 151.01 Writeup 11 (YOUR NAMES)
- Read: Local bindings for Wednesday’s class.
- Read: A computer scientist’s perspective of data science for Wednesday’s class [Should be ready late tonight].
- Exam 1
- Exam due TOMORROW night
- Cover sheet due Wednesday in class
- Epilogue due Wednesday night
Extra credit (Academic/Artistic)
- CS Table, Tuesday at noon in PDR A: Activism
- CS Extras, Thursday at 4:15 in 3821, Study Abroad
Extra credit (Peer)
- Women’s soccer, Saturday
- Women’s soccer, Sunday
Extra Credit (Misc)
None at the moment.
Other Good Things
Exam questions
- Can you give me a hint on problem 2?
- Don’t use
substring - In the lab in which we had 42,000 things to deal with, I asked you to find the middle 5. How did you do that?
- On problem 1, do we have to support complex numbers as input?
- Yes.
- How do I generate a random six digit number?
(random 1000000)- How do I submit my exam?
- Name it 012345.rkt (substituting your random number)
- Send it to rebelsky@grinnell.edu as an attachment in an email message entitled “CSC 151.01 Exam 1” (or something similar)
- Can you explain the parameters to sublist?
- Starting position (inclusive) and ending position (exclusive),
just like in
substring - Can I use the
sublistprocedure I wrote in problem 2 for problem 5? - Sure.
- Can I use
string-length? - Sure.
- How should we write our examples or tests?
- You know how to write tests.
- Examples you will generally run in the interactions pane and then copy and paste the input/output to the definitions pane and then comment it out.
Notes from quiz 3
Part a: Documenting nearest multiple
;;; Procedure:
;;; nearest-multiple
;;; Parameters:
;;; val, a real
;;; n, a real
;;; Purpose:
;;; Find a multiple of n that is nearest to val.
;;; Produces:
;;; m, a real - a multiple of n
;;; Preconditions:
;;; n is not zero
;;; Postconditions:
;;; * m is a multiple of n. That is, m/n is an integer. (Alternately,
;;; the remainder of m/n is 0.) (There exists an integer i, such that
;;; m = i*n)
;;; * m is a nearest multiple of n to val. That is, for all other
;;; multiples of n, h, the |h - val| >= |m - val|
- Don’t rename the parameters to meaningless things, such as
value1andvalue2 - If you do want to rename them, choose more meaningful names.
- We always name the result in the Produces section.
- We always give a type in the Produces section
- We might add an additional note in the Produces section
- If we don’t know what a multiple is, we might say “7 is a multiple of 2 because when I multiply 2 by 3.5 I get 7.”
- the distance of h to val is no smaller than distance of m to val. By “distance” we mean the absolute value difference between the two values.
- Sam would call
nan integer, but it’s up to you. - What’s the nearest multiple of 4 to 10? (
valis 10,nis 4)
Part b: Testing
- Different tests! (That is, test different concepts)
- Make sure that your tests test valid inputs and outputs.
- If there are two nearest multiples, don’t assume one.
- If zero is not a valid
n, don’t use it asn.
Lab and Debrief
- How should I compare the two-letter state abbreviation to “IA”?
=- No. They are not numbers.=is for numberseq?- No.eq?does not always work the way you expect for strings.eqv?- No.eqv?does not always work the way you expect for strings.equal?- Yes.equal?works well as your default comparison.string=?- Yes. You know that they are strings.string-ci=?- Yes. And this is nice because it supports"ia".- Can I write a lambda-free solution to
in-iowa? - Sure.
- First we extract the state.
(section list-ref <> 4). - Next we compare to “IA”.
(section string-ci=? <> "IA"). - So we can just compose those two.
(o (section list-ref <> 4) (section string-ci=? <> "IA")) - Is there an easy way to write “between a and b”?
(section < a <> b)- How do I figure out if any city in IA lacks a longitude?
(filter (negate has-longitude) (filter in-iowa? zips))