600 likes | 769 Views
CS 60. Introduction to CS 60 and Racket. 2013-09-03 Wednesday – Week 0 Lecture 01. Lecture 01 – Learning Goals. Can find help (grutors, piazza, etc). Can write Racket functions using if , cond , let , quotient , and recursion! Can debug Racket code using test cases & trace
E N D
CS 60 Introduction to CS 60 and Racket 2013-09-03 Wednesday – Week 0 Lecture 01
Lecture 01 – Learning Goals • Can find help (grutors, piazza, etc). • Can write Racket functions using if, cond, let, quotient, and recursion! • Can debug Racket code using test cases & trace • Can trace recursion using the strategies of • Forward • Backwards • One step
Introductions... Colleen Lewis Olin 1280 lewis@cs.hmc.edu fan of swimming/sleeping fan of baking
CS 60 vs. CS 5 CS 5's goals Solving computational problems in one language (Python) Conveying some of CS's breadth; CS 60's goals Solving computational problems in several different languages! Understandingcomputational problems their difficulty and limitations solution principles and efficiency Conveying more of CS's depth I'm sure it's just a coincidence that this CS 60 stuff definitely seems more alien
Syllabus, briefly Lectures Mon/Wed : 2:45-4:00pm Key skills, topics, and their motivation Insight into the HW problems (what, why, how) laptops not encouraged Required! Let me know if you won’t make it iClickers starting Thursday Website http://www.cs.hmc.edu/courses/2014/fall/cs60/ Tutors and tutoring hours LOTS!! See website... Post anonymously or not Post to the whole class or “private” (Private goes to Colleen and grutors – if you include code) Email help Piazza! Office Hours Monday/Wednesday 4-4:55 (after class) & Tuesday 11:00-12:30 (in the LAC lab) OR by appointment
Tutoring Hours LAC Computer Lab (2nd floor)
Tutoring Hours LAC Computer Lab (2nd floor)
Important Dates • Take-home Racket Quiz • due Wednesday, Oct 8th 4:30pm • 50 points • time limit: 60 minutes • 1 page of notes (front + back) • Take-home Prolog Quiz • due Thursday, Oct 23rd 4:30pm • 50 points • time limit: 90 minutes • 1 page of notes (front + back) • Take-home Java Quiz • Due Thursday, Nov 20th 4:30pm • 50 points • time limit: 60 minutes • 1 page of notes (front + back) • In-class Final Exam • Monday, Dec 15th 2:00-5:00pm • 200 points • time limit: 3 hours • 4 pages of notes (front + back)
Grade Components and Grading • Weekly homework (12 total): 1200 points (~75%) • Racket Quiz: 50 points (~3%) • Prolog Quiz: 50 points (~3%) • Java Quiz: 50 points (~3%) • Final exam: 200 points (~13%) • Participation: 50 points (~3%) (define (score p) (cond ((>= p 0.95) "A") ((>= p 0.90) "A-") ((>= p 0.87) "B+") ((>= p 0.83) "B") ((>= p 0.80) "B-") ((>= p 0.70) "C range") ((>= p 0.60) "passing") (else "hopefully NA")))
Grade Components and Grading • Participation: • Asking/Answering questions on piazza • Attendance • In-class “quizzes” • (not performance based) • Being a good CS60 citizen • Weekly homework (12 total): 1200 points (~75%) • Racket Quiz: 50 points (~3%) • Prolog Quiz: 50 points (~3%) • Java Quiz: 50 points (~3%) • Final exam: 200 points (~13%) • Participation: 50 points (~3%)
Problem 1: fun! Don’t stress about tutorial parts 6-8 Problem 2 must be MORE fun!
DEMO: Calling Functions Not 3 + 4 Calling two functions?Work from the inside-out Someone designed these to make sense.EVERYTHING should make sense!
DEMO: Labeling Data String Helpful error messagesREAD THEM Label data
How to Label Data (define a (+ 2 3)) (define addFunc +) (define variable value) Keyword An expression Shouldn’t be an expression
How to label functions Formal parameters Function Name Body Keyword Actual argument values
DEMO: procedures/parens #t and #fare Booleans Procedures are just things No extra parens! Racket thinks the thing after a paren is a function
How to use if & cond (if <predicate> <true case> <false case> ) (cond [<test1> <result> ] [<test2> <result> ] [else <result> ]) (define (warm temp) (if (> temp 75) "warm" "cold")) (define (cool temp) (cond [(> temp 75) "hot"] [(< temp 65) "cold"] [ else "ok"]))
How to use Let (create new variables in definitions) (let ( [<variable1> <value1>] [<variable2> <value2>] ) <body> ) (define (spam) (let ([a 3] [b 4]) (+ a b) ))
Testing in Racket Import the library Sample test Sample output Run tests
Tracing in Racket Import the library Tell it to trace add42 Sample output It tells you what input add42 was run with!
Tracing in Racket (to Debug!) Import the library (require racket/trace) (trace fac) Use this to see what recursive calls get made
Write Test Cases Write simple cases first!
Methods for Tracing Recursive Code • Forward • Backward • One step
The Factorial Function (define (fact x) (if (<= x 1) 1 (* x (fact (- x 1)))))
Forward (define (fact x) (if (<= x 1) 1 (* x (fact (- x 1)))))
Forward (define (fact x) (if (<= x 1) 1 (* x (fact (- x 1)))))
Backward (define (fact x) (if (<= x 1) 1 (* x (fact (- x 1))))) (fact 1) = 1 (fact 2) = (* 2 (fact 1)) = 2 (fact 3) = (* 3 (fact 2)) = 6 (fact 4) = (* 4 (fact 3)) = 24 (fact 5) = (* 5 (fact 4)) = 120 (fact 6) = (* 6 (fact 5)) = 720
One Step (define (fact x) (if (<= x 1) 1 (* x (fact (- x 1))))) (fact 8) = (* 8 (fact 7)) What is (fact 7)?
Methods for Tracing Recursive Code • Forward • Backward • One step
Pair Programming • On some problems, you may pair program – do! • You must practice "pair programming" • both people at the computer at the same time • trade off "driver" and "navigator" every 30 mins • both people contribute to the solution • Individual problems must be completed individually • Be sure to read syllabus Collaboration Policy!
Estimating Time • Most people grossly underestimate how long it takes to program (not thinking about time to debug and test) • You appear incompetent at programming (not true) if you can’t estimate how long something will take. • This is one of the hardest things to learn!!! Start to practice now! For each task estimate how long it will take and keep track of how wrong you were
Computer Science & = AWESOME