CSC151, Class 51: Records Overview: * Grouping data * About records * Implementing records in Scheme * An example * Lab Notes: * In-class exam on Friday + Optional; Try it and decide after fifteen minutes to stay or go. + Closed book. Closed computer. + You may bring one page of notes. * No, you don't have to write a report on your project. Hi Alex! * Questions on take-home exam 3? * Extra credit for today's Math talk. * Sorry about "in jokes". > (less-than? 'a 4) BUG: a is not a valid thing to compare > (less-than? "a" 4) #f ; same as (less-than? "a" "4")a ---------------------------------------- Observation: We regularly group data items together Cartoon Hero and his/her sidekick ("Asterix" "Obelix") ("Fred Flinstone" "Barney Rubble") Buy/Sell/Free Board (transacation name email category comment price) Phone directory (last-name first-name department phone-number) Nile.com Disadvantages of this strategy * It may be hard to remember what goes where * It may be hard to remember the type of each thing Once you've decided on what goes in a data item, you should provide procedures to fill in and get the values (define get-hero (lambda (hero-and-sidekick) (car hero-and-sidekick))) (define bsf-price (lambda (bsf) (list-ref bsf 5))) BSF decided to represent their six-element thingys as lists. A vector would be better. Changing their code could be hard. Some of the times they use list-ref, they need to change it to vector-ref. Some of the times they use car, they need to change it to vector-ref. If they had started by writing and using bsf-price and company, they'd only have to update those procedures. Grouping together "this is how I want to represent my data" and "these are the procedures for manipulating those data" is a good thing. Vectors also allow you to change values. * Second moral. then update all of our bsf-xxx procedures and everything else would still work. Defining a simple record ; Design: A course grade entry is an N-tuple with ; Department ; Number ; Section ; Prof ; Grade (numeric) ; Vector of five elements (define grade-entry-get-department (lambda (grade-entry) (vector-ref grade-entry 0))) (define grade-entry-set-department! (lambda (grade-entry new-department) (if (not (string? new-department)) (error 'grade-entry-set-department "Departments are strings, you bozo!") (if (not (member new-department (list "CSC" "MAT" "ECN" "MUS" ...))) (error 'grade-entry-set-department (string-append "Sorry, we offer no courses in " department)) (else (vector-set! grade-entry 0 new-department))))) > (grade-entry-set-department! dans-cs-course 123) BUG Bozo > (grade-entry-set-department! dans-cs-course "BUS") Sorry, we offer no course in BUS Do the lab! This means you, too, Alex. BREAKING NEWS! STRATEGIC PLANNING COMMITTEE MEETS TOMORROW, 2-6 p.m in Chrystal Basement to select PLANNING DIRECTION 1) Merit scholarships for highly talented students (probably increasing number of international students) 2) "A Fine Liberal Arts College in a Prairie Setting" (No major changes from but some fine tuning of the status quo). 3) Connections with Iowa--Becoming the school of choice for Iowans 4) Focusing on student needs, desires, and quality of life 5) Focusing on faculty needs, desires, and quality of life ---------------------------------------- Bye Alex. Get better. Same to all of those who missed class because you're sick.