University of California, Berkeley
EECS Department - Computer Science Division
CS3L Once-a-Week (OaW) Lecture 3
Domain & Range, Abstraction
- What types are each of these?
- With inch-count, the spec said it took a list of two numbers. We saw:
- (define (inch-count (feet inches) ...
- (define (inch-count '(feet inches) ...
- What's wrong with
- (if (and (my-first-test foo) (my-second-test foo)) #t #f)
- (equal? bool #f)
- Why should we call other procedures if we can just do it ourselves?
- What does this do?
- What are good mnemonics for first and butfirst?
- What does (first (butfirst '(abc def ghi)) return and why?
- What does (butlast (butfirst '(abc def ghi)) return and why?
- The goal of lecture is to review Common Confusions, give demos, introduce high-level information, and share announcements (NOT work on exam-level questions)
- NOT to take dictation -- that's the purpose of handouts!! Eyes front, everyone...
- I (Dan) strive to be a perfect (7.0/7.0) teacher -- how can I improve? Tell me!
- You can go to ANYONE's lab (if there's room)
- We have 3 other websites
- ucwise : www.ucwise.org
- bspace : bspace.berkeley.edu
- WLA : wla.berkeley.edu
- The course recorded is an earlier CS3 with slightly different emphasis. Early lectures may work better than later ones (we deviate later). Very different lab experience (they don't learn as well as you do, more information has to happen in lecture). Same book, though!
- Dan's office hours: M10-11am in HFA C-30
- Cheating - serious, don't do it, we'll send folks to the Office of Student Conduct
- Giving away answers is as bad as receiving them
- TAsiT = TAs-in-Training (top students [our readers] who are pre-TAs)
- Homework 0 due in lecture now
- No readers this year -- all files available online
- Quest (half-way between a quiz and a test) scheduled in-class for 2009-02-09 ... in 1 week!
- 5% of total grade (basically, a sanity-check)
- Open-book, open notes (as are all our exams)
- Covers everything we've seen up to that date
- There will be a review session the weekend before
- Other admin questions?
Domain and Range
- What happens when our function is +, our first argument is 1 and our second argument is two?
- What is the domain of a function?
- The things a function accepts as an argument.
- What is the range of a function?
- All the possible return values of a function
- Examples: word sqrt sentence +
- Arguably the most important part of Computer Science
- Definition: “The process of leaving out of consideration one or more properties of a complex object so at to attend to others”
- How many of you know how to drive a car? How many of those know how a car works?
- You don’t need to know how code works as long as it adheres to specifications (domain, range, side-effects)
- E.g.: double, whose body can be (* 2 x) or (+ x x))
- This is the fundamental principle that allows for outsourcing!
- E.g.: I give my detailed specs to some programmer in some other country where the cost of programmer labor is cheaper and they return me (hopefully nonbuggy) code.
- You don’t need to know how we represent data internally, only how to manipulate it.
- We can make up an Abstract Data Type (ADT), allowing us to create a new type of data (other than numbers, words, sentences, booleans and procedures, all you know about so far) and manipulate it.
Data Abstraction Example ... let's make a school!
- What pieces make up a school?
- Let’s make a first attempt to write the school data type...
(define (make-school name mascot)
(word name mascot))
- Anything wrong? Let's write it again, correctly.
- Now let's play with it and write has-same-mascot?
- Now let's modify make-school to have a location too
- Does has-same-mascot? work?
- Let's make sure we have software reuse!!
In Lab this week you'll see...
- Difference between Dates, a Case Study dealing with how many days are spanned between two dates
- This is a recurring problem: e.g., height differences, currency differences, etc.
- A Case Study...
- starts with a problem statement, ends with a solution (in between, a story, or narrative)
- documents "How a program comes to be"
- is written by a programming expert, you walk through it with the author and understand what the expert thinks about the process
- is used to teach you the process of coding -- this is called the Apprentice model of learning.
- can make you a better programmer (4 out of 5 educational researchers believe this!)
In Life this week you'll see...
- Again, more economic bad news. IMHO, we're far from the nadir.
- The Steelers celebrating win #6.